In the previous method insert, the second ifstatement tests the value of newPosition. Should the boolean expression it tests be isEmpty() || (newPosition == 1)? Explain.
What will be an ideal response?
Although you could test for an empty list, such a test is not necessary. When a list is empty, itemCount is zero. The only acceptable position for an insertion is 1, because the boolean expression (newPosition >= 1)&& (newPosition <= itemCount + 1) will be true. Therefore, the body of the first ifstatement will execute, and the insertion into the empty list will occur correctly.
Computer Science & Information Technology
You might also like to view...
Which of the following shows the correct use of the final PHP keyword?
a. function operation(final) {} b. final function operation() {} c. function final operation() {} d. final function operation("final") {}
Computer Science & Information Technology
? Item #1 in the figure above is called a(n) ____________.
Fill in the blank(s) with the appropriate word(s).
Computer Science & Information Technology