Program to create a singly linked list in c
For singly linked list , you can traverse the list only in one direction. The diagram below shows an example of a singly linked list. It has four data nodes. Each node has an integer as value and a link to the next node. Linked list head always points to the first node and the last node always points to NULL. We can traverse the list from head to the last node but not in other direction. A linked list node is represented by a C structure struct with two parts, 1 value or data and 2 link.
We defined the value part as integer here but it can be arbitrarily complex. Each element in the singly linked list is called a node. Each node has two components: data and a pointer next which points to the next node in the list. The first node of the list is called as head, and the last node of the list is called a tail.
The last node of the list contains a pointer to the null. Each node in the list can be accessed linearly by traversing through the list from head to tail. Consider the above example; node 1 is the head of the list and node 4 is the tail of the list. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most visited in Data Structures. We use cookies to ensure you have the best browsing experience on our website. Start Your Coding Journey Now! The next part after the creation of a node is to join the nodes and create the linked list.
Try to understand the code by allocating two to three nodes by above mechanism and you will get it. Please login to view or add comment s. Become an Author Submit your Article. It's Simple and Conceptual. Get Python course for Days Hours Min Sec. Pro Course Features. Simple Videos. Questions to Practice. Solved Examples.
0コメント