Ad Code

6/recent/ticker-posts

Single Linked List : Create in simple way

Before starting , if you haven't read our previous posts about linked list then click here.

A single linked list made up of nodes which are connected through the link. A node contains two parts data and link. So for creating the single linked list we have to understand how to create a one node.

Lets understand through this code;

first we have taken the important libraries. Then we have created a one structure named as node. In which we have given data and also link as pointer. Further in main function we have created one head pointer initially assigned as null. By using malloc function we have allocated certain memory to the head pointer.

Now the main part comes, this step can create a major change in creating node as well as in creating a single linked list. We have to give data to the head then we have assigned address or link to the node,in example we have taken NULL. Then simply we have to printed the data using printf function

Now we have understood how to create node. we have to join or connect two nodes. The coding will be same as above but further part we have to add is,

For connecting two nodes we have to make another pointer similar as head pointer. In example we have created current pointer and assigned memory also. Now we have two nodes for joining the first node should contain the address of the second node, for that the main line is


Our list becomes ,

We have created two nodes in our single linked list. The creating third node and connect to the our list we will see in our next part

stay connected....!

Post a Comment

0 Comments

Ad Code