Ad Code

6/recent/ticker-posts

Single Linked List : Create in simple way (PART- || )

In previous part we have seen how to create the node and hoe to connect them to form a single list. If you haven't read that then click here

Now we have to add the third node in our linked list. There are two ways to add,

  1. By creating new pointer

  2. By using first head pointer.

By creating pointer

In this simply we have to create new pointer and have to connect to the 2nd node of our list as we have done in previous part. But imagine you are as a developer , you have to create the linked list consits of 40 nodes,there you can not use this traditional method.



By using head pointer

To create the linked list consists of infinite nodes this method is used, you ca use this for any linked list. The main trick behind this is this,


So understand it properly,lets say address of our second node is 2000 and of first is 1000. Now whet the first executes the value becomes 2000 , which means it points towards the second node of the list. Now again arrow operator does his execution and then the address points toward the third i.e. 3000 which is the address of our third. In simple word we are connecting third node using head pointer.
For more understanding see this flowchart,

Now we are done with our single linked list. You can do as more nodes as you want the technique is same. Our list is,

Stay connected...!

Post a Comment

0 Comments

Ad Code