chap15java4th
chap15java4th
Linked Data
Structures
Copyright © 2010 Pearson Addison-Wesley. All rights reserved. Copyright © 2010 Pearson Addison-Wesley.
All rights reserved.
Introduction to Linked Data Structures
temp "socks"
"socks"
temp
head position
2. Bypass the "shoes" node from the next link of the previous node
position.previous.next = position.next;
head position
head position
4. Picture redrawn for clarity with the "shoes" node removed since
there are no longer references pointing to this node .
null "coat" "socks”
head position
head position
2. Create new TwoWayNode with previous linked to "coat" and next to "shoes"
TwoWayNode temp = new TwoWayNode(newData, position.previous, position);
// newData = "shirt"
head
"shirt"
temp position
0 1 2 3 4 5 6 7 8 9
hashArray empty empty empty empty empty empty empty empty empty empty
cat
4. After adding "turtle" with hash of 2 – collision and chained to linked list with "cat"
0 1 2 3 4 5 6 7 8 9
hashArray empty empty empty empty empty empty empty
cat
6 public HashTable()
7 {
8 hashArray = new LinkedList2[SIZE];
9 for (int i=0; i < SIZE; i++)
10 hashArray[i] = new LinkedList2();
11 }
SAMPLE DIALOGUE
9 public Node( )
10 {
11 data = null;
12 link = null;
13 }
14 public Node(T newData, Node<T> linkValue)
15 {
16 data = newData;
17 link = linkValue;
18 }
19 }//End of Node<T> inner class
The clear, size, and isEmpty methods are identicalto those in Display 15.8
for the LinkedList3 class.
14 green.add("peas");
15 green.add("grapes");
16 green.add("garden hose");
17 green.add("grass");
SAMPLE DIALOGUE