我是靠谱客的博主 复杂爆米花,这篇文章主要介绍[C/C++标准库]_[初级]_[标准库里提供的排序算法]sort()stable_sort()partial_sort()reverse()nth_element()qsort() ,现在分享给大家,希望可以做个参考。
sort()
stable_sort()
partial_sort()
reverse()
nth_element()
qsort()
场景:
1. C/C++的algorithm里提供的算法一般是集合的排序,查询和修改。
2. 也只有在特定场景在会用到以下算法函数.
代码: test_sort.cpp
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
// sort
// stable_sort
// partial_sort
// reverse
// sort_heap
// nth_element
// qsort
//参考:http://www.cplusplus.com/reference/algorithm/is_sorted/
template <class ForwardIterator>
bool is_sorted (ForwardIterator first, ForwardIterator last)
{
if (first==last) return true;
ForwardIterator next = first;
while (++next!=last) {
if (*next<*first) // or, if (comp(*next,*first)) for version (2)
return false;
最后
以上就是复杂爆米花最近收集整理的关于[C/C++标准库]_[初级]_[标准库里提供的排序算法]sort()stable_sort()partial_sort()reverse()nth_element()qsort() 的全部内容,更多相关[C/C++标准库]_[初级]_[标准库里提供的排序算法]sort()stable_sort()partial_sort()reverse()nth_element()qsort()内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复