我是靠谱客的博主 复杂爆米花,最近开发中收集的这篇文章主要介绍[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() 所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复