Answer the question
In order to leave comments, you need to log in
What is the algorithm for sorting a singly linked list?
What should be the algorithm for sorting a singly linked list, in short), thanks
Answer the question
In order to leave comments, you need to log in
For a list, merge sort is fine. Unlike an array, lists do not need a second array to store temporary results (generally speaking, you can sort an array without it, but it turns out to be a slower and too complicated algorithm).
First, make a note that in modern programming practice, a linked list is not considered the first line of choice as a data store due to its hostility to caches and low performance as a result.
Choice sort is good:
-go to the end of the array, find the maximum
-exchange the maximum and the first element
-repeat, but start from the second element, then from the third, etc.
The complexity of this sort in O-notation is N^2.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question