Java Reference
In-Depth Information
Display 15.19
Deleting a Node
1. Existing list with the iterator positioned at “shoes”
"coat"
"orange juice"
"shoes"
"socks"
null
head
previous
position
2. Bypass the node at position from previous
previous.link = position.link;
"coat"
"orange juice"
"shoes"
"socks"
null
head
previous
position
3. Update position to reference the next node
position = position.link;
"orange juice"
"coat"
"shoes"
"socks"
null
head
previous
position
Since no variable references the node “shoes” Java will automatically
recycle the memory allocated for it.
4. Same picture with deleted node not shown
"coat"
"orange juice"
"socks"
null
head
previous
position
 
Search WWH ::




Custom Search