Linked List
Linked List
Linked List
each node contains one or more data fields and a pointer to the next node.
Every node in a linked list contains two parts, an integer and a pointer to
the next node. The left part of the node contains data
The right part of the node contains a pointer to the next node (or address
of the next node in sequence). The last node will have no next node
connected to it, so it will store a special value called NULL.
Both arrays and linked lists are a linear collection of data elements.
Like an array, insertions and deletions can be done at any point in the list
in a constant time
struct node
{
int data;
struct node *next;
};
Singly linked list:
A singly linked list is the simplest type of linked list in which every node
contains some data and a pointer to the next node of the same data type.
A singly linked list allows traversal of data only in one way.
Algorithm for traversing a linked list:
The PREV field is used to store the address of the preceding node, which
enables us to traverse the list in the backward direction. A doubly linked
list provides the ease to manipulate the elements of the list as it maintains
pointers to nodes in both the directions. The main advantage of using a
doubly linked list is that it makes searching twice as efficient