There are various types of linked list as follows:
- Singly Linked List
- Doubly linked List
- Circular Linked List
- Doubly Circular Linked List
Singly Linked List :
Singly linked list is a most common type of linked list in which each node consists of two parts :
- Information or data part
- Pointer to the next node.
If suppose the singly linked list consists of four(4) nodes then it is represented as,
In this type of linked list, each node contains a single pointer to the next node hence it is called as singly linked list.
Only forward sequential traversal is possible in singly linked list because pointer points to the next node in sequence.
C code for a node in the singly linked list is as follows ,
struct node
{
int data;
struct node *next;
}
Doubly Linked List :
In this type of linked list, each node contains two pointers i.e., one points to the next node in sequence and the other points to the immediate previous node.
A node in doubly linked list contains three information,
- Data information
- Pointer to the next node
- Pointer to the previous node
If suppose, the doubly linked list contains four nodes, then it is represented as,
First node has no previous node hence the pointer to the previous node is NULL.
Both forward and reverse sequential traverse is possible in doubly linked list.
C code for a node in the doubly linked list is represented as follows,
struct node
{
int data;
struct node *next;
struct node *prev;
}
Circular Linked List :
In circular linked list, the last node's pointer points to the first or head node in the list making it a circular path as shown below.
Doubly Circular Linked List :
A node in doubly circular linked list contains three information i.e.,
- Data information
- Pointer to the next node
- Pointer to previous node
The last node's pointer points to first or the head node and the first node's pointer points to the last node in the list making it a circular path.
I own a website www.coderlogs.com where in I write similar blogs so do visit this website for more such blog posts.
Top comments (0)