Java Reference
In-Depth Information
Display 15.24
Inserting a Node into a Doubly Linked List
1. Existing list with an iterator referencing “shoes”
null
"coat"
"shoes"
"socks"
null
head
position
2. Create new TwoWayNode with previous linked to “coat” and next t
o “shoes”
TwoWayNode temp = newTwoWayNode(newData, position.previous, position);
// newData = "shirt"
null
"coat"
"shoes"
"socks"
null
head
"shirt"
temp
position
3. Set next link from “coat” to the new node of “shirt”
position.previous.next = temp;
"shoes"
"socks"
null
null
"coat"
head
"shirt"
"shirt"
temp
position
4. Set previous link from “shoes” to the new node of “shirt”
position.previous =
temp;
"shoes"
"socks"
null
null
"coat"
head
"shirt "
temp
position
 
 
Search WWH ::




Custom Search