Why does java.util.Arrays.sort(Object[]) use 2 kinds of sorting algorithms?

后端 未结 4 1577
一生所求
一生所求 2020-12-23 20:42

I found that java.util.Arrays.sort(Object[]) use 2 kinds of sorting algorithms(in JDK 1.6).

pseudocode:

if(array.length<7)
   inserti         


        
4条回答
  •  隐瞒了意图╮
    2020-12-23 21:37

    It's for speed. The overhead of mergeSort is high enough that for short arrays it would be slower than insertion sort.

提交回复
热议问题