转载

Java 6中有哪些不同的排序算法?

有几种排序算法,如计算机科学教科书中经常讨论的插入排序,选择排序,冒泡排序等.给定一个整数或对象数组,是否有内置的Java 6语言API,让我选择应用特定的排序算法来排序数组而不是我再次重新发明这些轮子?如果没有内置到Java 6中,是否有开源库可以产生这种功能,它们是什么?

Arrays.sort() 方法在所有基本类型数组中使用快速排序.
The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy’s “Engineering a Sort Function”, Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

Collections.sort() 方法使用合并排序.这种类型也用于 Arrays.sort(Object[]) 和Arrays.sort(T [],Comparator<?super T>).

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n log(n) performance. This implementation dumps the specified list into an array, sorts the array, and iterates over the list resetting each element from the corresponding position in the array. This avoids the n2 log(n) performance that would result from attempting to sort a linked list in place.

翻译自:https://stackoverflow.com/questions/6818683/what-different-sorting-algorithms-are-available-in-java-6

原文  https://codeday.me/bug/20190111/511709.html
正文到此结束
Loading...