Linux Sort command
I would like to know which sorting algorithm the linux SORT command uses开发者_JAVA技巧?
mergesort
It1 uses mergesort rather than quicksort or heapsort for two reasons:
- mergesort is a stable sort and typically the efficient quicksort implementations are not
- while it may do more swaps or moves it does fewer comparisons and so tends to work better with text input
1. Linux distros are free to choose their own sort utility but I imagine virtually all use GNU sort so I have described that.
An External R-Way merge sort according to Algorithm details of UNIX Sort Command. Found via this stackoverflow question.
精彩评论