Sort Linked List Using Insertion Sort
Explore how to implement insertion sort on a linked list by moving nodes from the original list to a new sorted list. Understand the step-by-step process, time and space complexities, and practice this fundamental linked list algorithm.
We'll cover the following...
We'll cover the following...
Statement
We’re given the head pointer of a linked list. Sort the linked list in ascending order using insertion sort. Return the new head pointer of the sorted linked list.
Example
If the given linked list is 29 -> 23 -> 82 -> 11, then the sorted list should be 11 -> 23 -> 29 -> 82.
Sample input
[29, 23, 82, 11]
Expected output
[11, 23, 29, 82]