且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

STL C ++中更好的排序算法

更新时间:2023-02-26 16:46:35

请从您的问题中定义***" ...


以下是有关 STL 排序算法的一些信息:

-std::srot()-最快的替代方法.无法保证原始序列中的相等元素将在最终结果中保留其相对顺序.
-std::stable_sort()-比std::srot()慢,但将保留最终结果中相等元素的保留相对顺序.如果相对顺序很重要,请使用此算法.
-std::partial_sort()-使用它仅对序列的一部分进行排序.

顺便说一句:有时容器会提供自己的排序算法.例如std::list.

有关这些算法的其他详细信息和比较,请参见此处 [
Please define ''best'' from your question...


And here is some info on STL sort algorithms:

- std::srot() - the fastest alternative. There is no guarantee that equal elements in the original sequence will retain their relative orderings in the final result.
- std::stable_sort() - slower than std::srot() but will retain the retain relative orderings of equal elements in the final result. If the relative order is important use this algorithm.
- std::partial_sort() - use it to sort only a portion of a sequence.

BTW: Sometimes containers provide their own sort algorithms. For example std::list.

For additional details and comparison of these algorithms, see here[^].


希望 [ ^ ]可能会为您提供帮助.
Hope this[^] might help you.