Singly Linked List in C with Code and Explanation
Singly LinkedList (SLL)
A Singly Linked List is a linear data structure where each element (called a node) points to the next node in the sequence.
It is a dynamic structure, meaning it can grow or shrink in size during runtime. Structure of a Node:
Each node contains:
- Data: The value stored in the node.
- Next: A pointer/reference to the next node in the list.
There are Five operation in SLL:
1) Insert - Insert the element in our node like, insert(34);
insert(3);
insert(4);
2) Traverse - Print all inserted element like, 34->3->4->NULL
3) Delete - We can delete the inserted element like, I want to delete element delete(3); over this result =34->3->4->NULL, so we get after delete the element of delete(3); then we get like this, 34->4->NULL
4) Search - In search operation, if you want to search element like 4, 4 is present in node or not so, on that time we can perform search operation.
5) Reverse - Reverse the original order like from this 34->3->4->NULL to 4->3->34->NULL
Code for Singly Linked List:
--------------Traversing node --------------- 34 -> 89 -> 30 -> 98 -> 45 -> NULL --------------After deleting node --------------- 89 -> 30 -> 98 -> 45 -> NULL -------------- Searching LL --------------- Element 45 found at 5 node -------------- Reversing LL ---------------
45 -> 98 -> 30 -> 89 -> NULL
Comments
Post a Comment