Singly Linked List:
Singly Linked List is a collection of ordered set of elements. A Node in singly linked list has two parts – data part and link part. Data part of the node contains the actual information which is represented as node. Link part of the node contains address of next node linked to it.
It can be traversed in only one direction because the node stores only next pointer. So, it can’t reverse linked list.
Algorithm for Insertion Sort for Singly Linked List :
- Create an empty sorted (or result) list
- Traverse the given list, do following for every node.
- Insert current node in sorted way in sorted or result list.
- Change head of given linked list to head of sorted (or result) list.
Insertion Sort for Singly Linked List:
In C language, program is given below:
Linked List before sorting 30 3 4 20 5 Linked List after sorting 3 4 5 20 30