排序小整数数组的最佳排序算法是什么?

问题描述:

根据问题标题,如果数组的长度为奇数且数组元素的编号为1 - 10.

As per question title, if the array is of an odd length and the array elements are numbered 1 - 10.

示例,


3 6 8 1 3 7 7 9 4 1

3 6 8 1 3 7 7 9 4 1

我是想使用 heapsort ?由于它是一个数组,合并排序插入排序需要转移,并且效率不高。

I was thinking of using heapsort? Since it is an array, merge sort and insertion sort requires shifting, and would not be so efficient.


数组元素的数字是1 - 10.

the array elements are number from 1 - 10.

有了这个限制,计数排序将比任何通用排序算法更有效 - 它是O( n)

With this restriction, counting sort will be far more efficient than any general purpose sorting algorithm - it's O(n)