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 10, 2021 at 2:04pm IST

Linked List insertion can be done using three ways,

1) Insertion of a new node at front of a given node.

2) Insertion of a new node after a given node.

3) Insertion of a new node at the end of the node.

In this tutorial, we will see how to insert a new node after a given node in Linked List. To understand this lets see the first scenario in which the original Linked list contains a head pointer pointing to First Node. The first node is pointing towards the second Node containing value 2. Second Node point towards the third node containing value 3. At last, the third Node points towards NULL.

1) Original Linked list contains a head pointer pointing to First Node.

2) First Node points to second Node containing value 2.

3) Second Node points to the third node containing value 3.

4) Third Node points to NULL.

Now if we want to insert a node at the end of a given node of a linked list, an algorithm for that would be like this,

1) Head point towards the first Node containing value 1.

2) First Node points to the second Node containing value 2.

3) Second Node points to the third node containing value 3.

4) **New Node's** next points to NULL.

5) Third node's next points to New Node.

Now, have a look at the second scenario in which we are going to insert a node after a given node. For that thing to happen, Head point towards the first Node containing value 1. Then the first Node points to the second Node containing value 2. Then the second node points to the third node containing value 3. **New Node's** next points to NULL. At last, third node's next points to New Node.

So, this is how we can manipulate the nodes to insert and get the results in the linked list. Lets see a C function on how to insert a node at the end of a given node in the linked list.

void insertNodeAtend(struct node** head_ref, int new_data) {/* 1. allocate node */struct node* new_node = (struct node*) malloc(sizeof(struct node)); struct node *last = *head_ref; /* used in step 5*//* 2. put in the data */new_node->data = new_data;/* 3. This new node is going to be the last node, so make next of it as NULL*/new_node->next = NULL;/* 4. If the Linked List is empty, then make the new node as head */if (*head_ref == NULL) { *head_ref = new_node; return; }/* 5. Else traverse till the last node */while (last->next != NULL) last = last->next;/* 6. Change the next of last node */last->next = new_node; return; }