STL中的Sort算法

STL 中的Sort排序算法是一种动态选择底层的排序算法的包装排序算法
选择的关键决定于待排序的数据规模。当数据量非常大的时候采用Quick Sort,分段递归排序。有时候为避免Quick Sort递归调用带来的额外负荷
(overhead),就会改用Insertion Sort 如果递归层次过深还会改用Heap Sort。
Insertion Sort采用双层循环的形式进行,外循环遍历整个序列。每次迭代决定出一个子区间。内循环遍历子区间将每一个逆转对进行调整。
逆转对(i < j,*i > *j); 复杂度为O(N^2);
Insertion Sort 提供了两个版本
:加双下划线表示内部使用
template
void __insertion_sort(RandomAccessIterator first,
RandomAccessIterator last)
{
if(first == last)
{
return ;
}
for(RandomAccessIterator i = first+1; i != last; ++i)//外循环
{
__linear_insert(first, i, value_type(first));
//[first,i)形成一个子区间
}
}

template

发布了13 篇原创文章 · 获赞 6 · 访问量 9404

猜你喜欢

转载自blog.csdn.net/u010843408/article/details/45888029