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

栏目: 编程工具 · 发布时间: 6年前

内容简介:有几种排序算法,如计算机科学教科书中经常讨论的插入排序,选择排序,冒泡排序等.给定一个整数或对象数组,是否有内置的Java 6语言API,让我选择应用特定的排序算法来排序数组而不是我再次重新发明这些轮子?如果没有内置到Java 6中,是否有开源库可以产生这种功能,它们是什么?翻译自:https://stackoverflow.com/questions/6818683/what-different-sorting-algorithms-are-available-in-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


以上所述就是小编给大家介绍的《Java 6中有哪些不同的排序算法?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Effective Objective-C 2.0

Effective Objective-C 2.0

Matt Galloway / 爱飞翔 / 机械工业出版社 / 2014-1 / 69.00元

《effective objective-c 2.0:编写高质量ios与os x代码的52个有效方法》是世界级c++开发大师scott meyers亲自担当顾问编辑的“effective software development series”系列丛书中的新作,amazon全五星评价。从语法、接口与api设计、内存管理、框架等7大方面总结和探讨了objective-c编程中52个鲜为人知和容易被忽......一起来看看 《Effective Objective-C 2.0》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具