在std :: sort()中使用了哪种类型的排序? [英] Which type of sorting is used in the std::sort()?
问题描述
任何人都可以告诉我在 std :: sort()$ c中实现了哪种类型的排序技术(冒泡,插入,选择,快速,合并,计数...) $ c>
Can anyone please tell me that which type of sorting technique (bubble, insertion, selection, quick, merge, count...) is implemented in the std::sort()
function defined in the <algorithm>
header file?
推荐答案
p> std :: sort
的大多数实现使用快速排序(或通常是混合算法,如introsort,它结合了快速排序,排序和插入排序)。
Most implementations of std::sort
use quicksort, (or usually a hybrid algorithm like introsort, which combines quicksort, heapsort and insertion sort).
标准只需要 std :: sort
根据指定的顺序排序数据,复杂度约为O N log(N));它不能保证稳定。技术上,introsort比quicksort更好地满足复杂性要求,因为quicksort具有二次最坏情况时间。
The only thing the standard requires is that std::sort
somehow sort the data according to the specified ordering with a complexity of approximately O(N log(N)); it is not guaranteed to be stable. Technically, introsort better meets the complexity requirement than quicksort, because quicksort has quadratic worst-case time.
这篇关于在std :: sort()中使用了哪种类型的排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!