737 |
|
} |
738 |
|
|
739 |
|
/** |
740 |
< |
* Unlike other traversal methods, iterators need to handle: |
740 |
> |
* Returns the next live successor of p, or null if no such. |
741 |
> |
* |
742 |
> |
* Unlike other traversal methods, iterators need to handle both: |
743 |
|
* - dequeued nodes (p.next == p) |
744 |
< |
* - interior removed nodes (p.item == null) |
744 |
> |
* - (possibly multiple) interior removed nodes (p.item == null) |
745 |
|
*/ |
746 |
|
private Node<E> nextNode(Node<E> p) { |
747 |
< |
Node<E> s = p.next; |
748 |
< |
if (p == s) |
749 |
< |
return head.next; |
750 |
< |
// Skip over removed nodes. |
751 |
< |
// May be necessary if multiple interior Nodes are removed. |
752 |
< |
while (s != null && s.item == null) |
753 |
< |
s = s.next; |
754 |
< |
return s; |
747 |
> |
for (;;) { |
748 |
> |
Node<E> s = p.next; |
749 |
> |
if (s == p) |
750 |
> |
return head.next; |
751 |
> |
if (s == null || s.item != null) |
752 |
> |
return s; |
753 |
> |
p = s; |
754 |
> |
} |
755 |
|
} |
756 |
|
|
757 |
|
public E next() { |