We have discussed Insertion Sort for arrays. In this article same for linked list is discussed.
Below is simple insertion sort algorithm for linked list.
1) Create an empty sorted (or result) list 2) Traverse the given list, do following for every node. ......a) Insert current node in sorted way in sorted or result list. 3) Change head of given linked list to head of sorted (or result) list.
The main step is (2.a) which has been covered in below post.
Sorted Insert for Singly Linked List
Below is implementation of above algorithm
Linked List before sorting 30 3 4 20 5 Linked List after sorting 3 4 5 20 30
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Circular Singly Linked List | Insertion
- Convert singly linked list into circular linked list
- Difference between Singly linked list and Doubly linked list
- Convert Singly Linked List to XOR Linked List
- Recursive selection sort for singly linked list | Swapping node links
- Doubly Circular Linked List | Set 1 (Introduction and Insertion)
- Doubly Linked List | Set 1 (Introduction and Insertion)
- Recursive insertion and traversal linked list
- Insertion in Unrolled Linked List
- Insertion at Specific Position in a Circular Doubly Linked List
- Insertion in a sorted circular linked list when a random pointer is given
- Given only a pointer/reference to a node to be deleted in a singly linked list, how do you delete it?
- Alternating split of a given Singly Linked List | Set 1
- Reverse alternate K nodes in a Singly Linked List
- QuickSort on Singly Linked List
- Select a Random Node from a Singly Linked List
- Alternate Odd and Even Nodes in a Singly Linked List
- Find middle of singly linked list Recursively
- Binary Search on Singly Linked List
- C Program to reverse each node value in Singly Linked List