148. Sort a Linked List
Challenge1000 ms256 MBSolved by 0%
Sort the list into ascending order and print it.
Print Empty for an empty list.
With up to 100000 nodes, a bubble sort over the list will not finish in time.
Constraints - `0 ≤ n ≤ 100000` - `-1000000 ≤ value ≤ 1000000`
Input
The first line contains an integer n, the number of nodes.
The second line contains n space-separated integers, the node values from head to tail.
The starter code builds the list for you; work on the nodes, not the array.
Output
Print the sorted list from head to tail on ONE line, separated by single spaces, or Empty for an empty list.
Input5
4 2 1 5 3
Output1 2 3 4 5
Noteis a scrambled list
Input5
1 2 3 4 5
Output1 2 3 4 5
Noteis already sorted
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.