- A 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).

A linked list is a collection of a node having the following format.

Above node contain two fields of a different type in a node. Therefore to implement a node we use a type of structure to form a node.

1 2 3 4 5 |
Struct node { int data; Struct node * next; } |

In which data stores int type data in a node and the next pointer points next node of the same type structure.

Now we will see how exactly the linked list be implemented in C.

## Linked list program in c

In this we simply create a linked list with 3 nodes P1, P2, P3 As given below.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include<stdio.h> Struct node { int data; Struct node *next; } void main() { 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)); p1->next=p2; p2->next=p3; p3->next=NULL; start=p1; temp=start; temp->data=10; temp=temp->next; temp->data=20; temp=temp->next; temp->data=30; temp=temp->next; temp=start; //Display Linked List printf("%d",temp->data); temp=temp->next; printf("%d",temp->data); temp=temp->next; printf("%d",temp->data); temp=temp->next; } |

In an above linked list, We simply create nodes in c and for creating and allocating an address to the node we used **malloc()** which allocates memory dynamically and after that, we linked the nodes.

**Example:**

**p1 –> next = p2**, p1 stores address of p2 which forms a link.

In this way, we formed a linked list and stored data in it with the address.

## Types of Linked List

## Operations on linked list

### 1. Insert at beginning

This operation state that to insert the node at beginning of a linked list.

**Example:** Insert 10 at the beginning.

Insert 7 at the beginning.

Before adding a node to beginning it starts node but after adding at beginning new node become start.

### 2. Insert at end

This operation is to add a new node at last of LL.

After adding a node at end null be replaced by the address of a new node.

### 3. Insert before

This operation is to add a new node before any previously given node.

After adding new node we have to modify the address of the previous node and add that to new node added.

### 4. Deletion of node

This operation is to delete modes of the LL.

### 5. Destroy

To delete complete LL.

## Leave a Reply