来自Arrays.sort源代码:
public static void sort(int[] a) {
sort1(a, 0, a.length);
}然后:
private static void sort1(int x[], int off, int len) {
// Insertion sort on smallest arrays
if (len < 7) {
[...]
}
[...]
if (len > 7) {
[...]
}
[...]
}这个神奇的数字7是从哪里来的,为什么?
Link to the source code
发布于 2013-07-27 00:22:51
我相信当列表变得足够小时,Java排序算法会从合并排序切换到快速排序。源代码引用了一个文本,如果你很好奇的话,你可以去那里看看。
https://stackoverflow.com/questions/17886309
复制相似问题