R
R
rostyslavvvv2021-02-28 16:14:34
Algorithms
rostyslavvvv, 2021-02-28 16:14:34

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

2 answer(s)
W
Wataru, 2021-02-28
@wataru

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).

A
Armenian Radio, 2021-02-28
@gbg

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 question

Ask a Question

731 491 924 answers to any question