How to sort nearly sorted array in the fastest time possible? (Java)

前端 未结 10 2170
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 06:14

I have an array of values which is almost, but not quite sorted, with a few values displaced (say, 50 in 100000). How to sort it most efficiently? (performance is absolutely

10条回答
  •  猫巷女王i
    2020-12-30 06:54

    [Sun] JDK7 has (or will have) an implementation of Tim sort (from Python). It's a merge sort that takes advantage of order already existing in the array.

提交回复
热议问题