Leetcode Problem 147. Insertion Sort List

147. Insertion Sort List

Leetcode Solutions

Insertion Sort on a Singly Linked List

  1. Create a dummy node to serve as the new sorted list's head.
  2. Iterate through the original list.
  3. For each node, use two pointers to find the correct insertion point in the sorted list.
  4. Insert the node between the two pointers.
  5. Continue until all nodes from the original list are inserted into the sorted list.
  6. Return the next node of the dummy node, which is the head of the sorted list.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...