So, we have to write a C program that creates and traverses the singly linked list. Take care while handling the pointers in the program, because there are a lot of pointer movements.
Also read: Singly Linked List
Declaring a Singly Linked List:
So, we know that we can declare elements (nodes) of singly linked list using self referential structure.
Example of self referential structure:
Function Definition:
In our program two functions must be present i.e. first function to create the singly linked list and second to traverse the singly linked list.
- void create_list(int); This function helps to create the singly linked list. create_list() function takes an integer as an argument that creates the number of nodes in the singly linked list and returns nothing.
- void traverse(void); This function helps to traverse the singly linked list. traverse() function takes nothing as input and returns nothing.
C program for Create and Traverse Singly Linked List:
Output:
![](https://i0.wp.com/explore.techenutia.com/wp-content/uploads/2021/06/image-3-300x109.png?resize=300%2C109&ssl=1)
This is how our singly linked list looked like:
![](https://i0.wp.com/explore.techenutia.com/wp-content/uploads/2021/06/sd-2B-25281-2529-2B-25281-2529-300x134.png?resize=300%2C134&ssl=1)
Be First to Comment