How to sort an integer array into negative, zero, positive part without changing relative position?

前端 未结 5 1402
梦毁少年i
梦毁少年i 2021-02-04 08:31

Give an O(n) algorithm which takes as input an array S, then divides S into three sets: negatives, zeros, and positives. Show how to implement this in place, that is, without a

5条回答
  •  野的像风
    2021-02-04 09:06

    This is an instance of the Dutch national flag problem studied by Edsger Dijkstra. It's interesting in that no stable solution to this problem is known that runs in O(n) time and O(1) space (or at least, the last time I checked the literature, no known solution to the problem exists).

提交回复
热议问题