STL C ++中更好的排序算法 [英] Better sort algorithm in STL C++

查看:87
本文介绍了STL C ++中更好的排序算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪种是对std :: vector进行排序的最佳STL算法?
我的意思是我必须使用"partial_sort,sort,stable_sort ..".

Which is the best STL algorithm to sort a std::vector ?
i mean which i have to use "partial_sort, sort, stable_sort.."

推荐答案

请从您的问题中定义最佳" ...


以下是有关 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.


这篇关于STL C ++中更好的排序算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆