稳定排序2有价值的阵列? [英] Stable sort of 2 valued array?
本文介绍了稳定排序2有价值的阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有对象的数组。该对象有一个布尔值,在其中,我想作为重点用于排序的阵列(真实的所有对象都以虚假的所有对象之前),但在其他方面把事情按相同的顺序。
I have an array of objects. the objects have a Boolean value in them that I want to use as a key for sorting the array (all objects with true come before all objects with false) but otherwise leave things in the same order.
有一个简单的,就地,为O(n)解决方案呢?也许基数排序?
Is there a simple, in-place, O(n) solution to this? Maybe some variant of radix-sort?
推荐答案
请参阅这里关于这个话题的讨论。你可以基本上要么一个O(n)的-solution它需要额外的空间或为O(n log n)的就地解决方案。
See here for a discussion on this topic. You can basically have either an O(n)-solution which needs additional space or a O(n log n) in-place solution.
这篇关于稳定排序2有价值的阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文