博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
std::sort的详细用法
阅读量:2384 次
发布时间:2019-05-10

本文共 994 字,大约阅读时间需要 3 分钟。

#include 
2 #include
3 #include
4 #include
5 6 int main() 7 { 8 std::array
s = { 5, 7, 4, 2, 8, 6, 1, 9, 0, 3 }; 9 10 // sort using the default operator<11 std::sort(s.begin(), s.end());12 for (auto a : s) {13 std::cout << a << " ";14 }15 std::cout << '\n';16 17 // sort using a standard library compare function object18 std::sort(s.begin(), s.end(), std::greater
());19 for (auto a : s) {20 std::cout << a << " ";21 }22 std::cout << '\n';23 24 // sort using a custom function object25 struct {26 bool operator()(int a, int b) const27 {28 return a < b;29 }30 } customLess;31 std::sort(s.begin(), s.end(), customLess);32 for (auto a : s) {33 std::cout << a << " ";34 }35 std::cout << '\n';36 37 // sort using a lambda expression 38 std::sort(s.begin(), s.end(), [](int a, int b) {39 return b < a;40 });41 for (auto a : s) {42 std::cout << a << " ";43 }44 std::cout << '\n';45 }

转载地址:http://qwdab.baihongyu.com/

你可能感兴趣的文章
Oracle的导入导出
查看>>
抽象工厂模式
查看>>
享元模式
查看>>
解释器模式
查看>>
代理模式
查看>>
单例模式
查看>>
状态模式
查看>>
实现简单的Makefile工程管理器
查看>>
gdb调试工具的基本命令
查看>>
vim编辑器的常用命令
查看>>
linux中文件操作的常用命令总结
查看>>
添加SSH公钥来实现免密码登录
查看>>
学生管理系统,链表的增删改查,C语言文件操作,动态内存的分配和使用
查看>>
动态内存分配和释放:malloc,realloc,calloc,free函数
查看>>
使用qsort对结构体指针数组根据compare规则进行排序
查看>>
Linux 基于文件描述符的文件操作 open,close,read,write,lseek,stat,fstat,ftruncate
查看>>
linux 文件及目录操作 chmod,getcwd,chdir,mkdir,rmdir,opendir,readdir,seekdir,telldir、closedir、stat、fstat
查看>>
Linux IPC 信号 kill,signal,sigaction,sigprocmask,sigpending信号处理机制
查看>>
Linux IPC 共享内存 ,System V 共享内存机制: shmget,shmat,shmdt,shmctl
查看>>
Linux IPC 消息队列 创建访问 msgget,发送信息 msgsnd,接受信息 msgrcv,删除 msgctl
查看>>