In the figure on
the previous page, there is a linked list that contains five nodes with
data elements as 2, 6, 8, 7 and 1. The
current pointer is pointing to the node with element as 8.
We want to insert a new node with data element 9. This new node
will be inserted at the current position (the position where the
current pointer is pointing to). This insertion operation is
performed in a step by step fashion.
- The first step is to point next pointer of the new node (with data
element as 9) to the node with data element as 7.
- The second step is to point the next pointer of the node with data
element 8 to the node the new node with data element 9.
- The third step is to change the current pointer to point to
the new node.
Now, the updated linked list has
nodes with data elements as 2, 6, 8, 9,
7 and 1. The list size has become 6.
|