Page 19 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 19
Advanced Data Structure and Algorithms
Notes This statement creates space for two nodes each containing two empty fields as shown below:
Figure 1.5: Creation of the two Nodes
node1
Node1.value
Node1.next
node2
Node2.value
Node2.next
The next pointer of node1 can be made to point to node2 by the statement
node1.next=&node2;
This statement stores the address of node2 into the field node1.next and thus establishes a “link”
between node1 and node2 as shown below:
Figure 1.6: Node 1 Pointing to Node 2
node1
node1.value
node1
node1.value
Address of node2
node2
link
node2.value
node2.next
Now we can assign values to the fi eld value.
node1.value=30;
node2.value=40;
The result is as follows:
Figure 1.7: The Complete List of two Nodes
node1
30
871800
node2
link 40
node2.next
Assume that the address of node2 is 871800. As you can see, that address is now stored in the
next field of node1.
14 LOVELY PROFESSIONAL UNIVERSITY