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

前端 未结 10 2175
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  清歌不尽
    2020-12-30 06:42

    Cocktail Sort

    If you want a simple algorithm that's easy to implement, you could do a cocktail sort. It would work reasonably well on nearly-sorted input.

提交回复
热议问题