1. What is the difference between Array List and Linked List ?
2. Inserting a node at the beginning of linked list
3. Insert a node after a given node in linked list
4. How to insert a node at the end of a given node? - Codzify.com Tutorials
5. Bubble Sort Algorithm with practical program in C
6. Insertion Sort Algorithm with practical program in C
7. Merge Sort Algorithm with practical program in C
8. BFS and DFS in Data Structure | Inorder, Preorder and Postorder Traversal with practical example.
9. Kruskals Algorithm with practical example
10. How to calculate the complexity of Algorithms?
11. How to insert a new node after a given node in a linked list? - Codzify.com Tutorials
12. How to insert a new node after a given node in a linked list? - Codzify.com

**Article by:** Manish Methani

**Last Updated:** October 12, 2021 at 8:04am IST

Till now we have studied the arrays, right? Arrays are used to store data of the same type. In arrays, we must know the size of the array. That's why an array size is fixed every time.

Assume there is an array like this,

10 | 30 | 40 | 50 | 60 | 70 |

Now suppose you want to add element 20 at the first index after 10. Now to insert 20 after 10 you have to shift everything one position towards the right. So a shifted array looks like this,

10 | 20 | 30 | 40 | 50 | 60 | 70 |

Now think for a while, how expensive an operation of shifting an element of the array is. Now suppose you have to remove element 30 from the given array. So you have to shift all the elements towards the left. The solution to this shifting operation is a well-known Data Structure known as the Linked list in Data Structures.

**ArrayList vs Linked List**

The difference between Array List and the Linked List is explained here by the advantages of Linked List over Arrays.

1) Dynamic size 2) Insertion/Deletion is easy in Linked List.

The linked list is a linear data Structure used to store the elements dynamically. No need to know the actual size. In the case of arrays, you must know the size of an array. Linked List in Data Structure gives better advantages than arrays.

Head | | V +---+-----+------ +----+----+------ +----+----+----- | Data | Pointer|-----> | Data | Pointer| ------> | Data | NULL | +---+-----+------ +----+----+------ +----+----+-----

Linked List is created using nodes. Each node contains **Data** and **Pointer**. And each Pointer is attached with Next pointer. And the end Pointer contains **NULL** to indicate that the linked list is finished. The first Node is **HEAD** always.

C program to understand the concept of the linked list in Data Structures

head first Second | | | | | | V | | +---+---+ +---+---+ +----+------+ | 1 | o----->| 2 | o-----> | 3 | NULL | +---+---+ +---+---+ +----+------+

// A simple C program to introduce a linked list in DataStructures#include struct node { int data; struct node *next; };/* Program to create a simple linked list with 3 nodes */int main() { struct node* head = NULL; struct node* first = NULL; struct node* second = NULL;/* allocate 3 nodes in the heap */head = (struct node*)malloc(sizeof(struct node)); first = (struct node*)malloc(sizeof(struct node)); second = (struct node*)malloc(sizeof(struct node)); head->data = 1;//assign data in head nodehead->next = first;// Link head node with the first nodefirst->data = 2;//assign data to first nodefirst->next = second;// Link first node with the second nodesecond->data = 3;//assign data to second nodesecond->next = NULL; return 0; }

**The comments given are self-explanatory.** What we did is first we have allocated the three Nodes using the malloc() function. We named it as the **head**, **first**, the **second node**. We added the data in the **head** node and then linked it with the **first** node. Then we added data to the **first** node and linked it with the **second** node. Then we added data to the **second** node and then added **NULL** to indicate the end of the linked list.

It's easy if you looked at the program carefully. **Just three boxes.** Add data into it and link it to the next node. Now you can create any number of nodes you want.

I hope you have got the concept of how to create a node in the linked list with the C Program. Tada! Also, check out the related articles which you might love to read. They are given in the below section.