- Linked list is a linear type of data structure.
- It is a set of data which has data along with the address stored in it.
- Linked list store the data and address in a node.
- Node:- Node is a combination of data and the next (address of next node).
Linked list is a collection of node having following format.
Above node contain two field of different type in a node. Therefore to implement a node we use a type of structure to form node.
Struct node * next;
In which data stores int type data in a node and the next pointer points next node of a same type structure.
Now we will see how exactly the linked list be implemented in C.
In this we simply create a linked list with 3 nodes P1, P2, P3 As given below.
Struct node *next;
Struct node *p1,*p2,*p3;
Struct node *start,*temp;
p1=(Struct node*)malloc(sizeof(struct node));
p2=(Struct node*)malloc(sizeof(struct node));
p3=(Struct node*)malloc(sizeof(struct node));
//Display Linked List
In above linked list, We simply create nodes in c and for creating and allocating address to node we used malloc() which allocates memory dynamically and after that we linked the nodes.
p1 –> next = p2, p1 stores address of p2 which forms a link.
In this way we formed linked list and stored data in it with address.
Types of Linked List
Operations on linked list
1. Insert at beginning
This operation state that to insert node at beginning of linked list.
Example:- Insert 10 at beginning.
Insert 7 at beginning.
2. Insert at end
This operation is to add new node at last of LL.
3. Insert before
This operation is to add new node before any previous given node.
4. Deletion of node
This operation is to delete modes of the LL.
To delete complete LL.