Java Reference
In-Depth Information
if (position == null)
return first ! = null;
else
return position.next ! = null;
}
. . .
}
Removing the last visited node is more involved. If the element to be removed is the
first element, we just call removeFirst . Otherwise, an element in the middle of the
list must be removed, and the node preceding it needs to have its next reference
updated to skip the removed element (see Figure 6 ). If the previous reference
equals position , then this call to remove does not immediately follow a call to
next , and we throw an IllegalStateException .
Implementing operations that modify a linked list is challengingÈŒyou need to
make sure that you update all node references correctly.
Figure 6
Removing a Node from the Middle of a Linked List
675
Search WWH ::




Custom Search