Comp Sci Ab Urgent

<p>in 5 steps to a 5, on AB practice test 1, question 34, i seroiuslly think the book is wrong. here’s what it says</p>

<p>LinkedList data = <filled with=“” data=“” via=“” some=“” method=“”>;
Iterator it = data.iterator();
for(int pos = 0; pos < data.size()-1; pos++)
{
Object thisItem = it.next();
if(thisItem.equals(it.next())
System.out.println(it.next() + “was found in consecutive positions.”);
}
}</filled></p>

<p>Which of the following best describes when an error will occur?
A. always
B. whenever the list is nonempty
C. whenever the list size is a multiple of 3
D. depends on the actual data in the LinkedList
E. no exception</p>

<p>I say B because if you have the LinkedList { 1,2,3,4,5,6,7,8,9}, then during the first iteration of the for loop, it will compare 1 and 2. BUT, during the 2nd iteration of the loop, it will compare 3 and 4 rather than 2 and 3. so i say that its not comparing 2 and 3 to see if they’re equal, so i but B. the book says D on the basis that the iterator moves forward one too many ONLY times when you have do have consecutive terms, but i have just shown that it moves too much even without consecutive terms.</p>

<p>can anybody help me figure this out?</p>

<p>I think it might be because when you call it.next(), it changes the placement of the iterator, as in it functions like x++ and not like x+1.</p>

<p>could be wrong, haven’t gotten there in my studying yet, lol</p>

<p>It depends on whether you transcribed the question correctly–whether or not it’s x++, x+=2, x+=3.</p>

<p>If the question is as you explained it, then you are indeed correct. If it is x+=2, then you are not correct; counterexample: {1,1,2}.</p>

<p>Trust me on this one. I do the USA Computing Olympiad, which ASSUMES you’re completely comfortable with programming in general and moves immediately on to algorithm development.</p>

<p>PM me if you have more questions.</p>