Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果数组包含重复元素,那么哪种数据结构更适合排序?
B树可以工作吗?
对于固定且小范围的元素值,您可以使用计数排序算法,如此处所述。它的复杂性是,数组的大小O(n + k)在哪里,基本上是不同可能元素的数量。nk
O(n + k)
n
k
重点是计算相同元素的数量,然后以正确的顺序插入它们。