c++ STL排序

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using std::string;
using std::cout; using std::endl;
using std::vector;

int main()
{
   
	vector<int> a{
   4,2,3,5,1,8,6};

    
    std::sort(a.begin(),a.end(),std::greater<int>());    
    cout<<"从大到小: ";
    for(auto item : a) cout<<item<<" ";
    cout<<endl;
    
    std::sort(a.begin(),a.end(),std::less<int>());    
    cout<<"从小到大: ";
    for(auto item : a) cout<<item<<" ";
    cout<<endl;

    return 0;
}

结果

在这里插入图片描述

相关推荐

  1. 什么是CSTP测试认证,如何通过CSTP认证?

    2023-12-29 23:26:01       28 阅读
  2. <span style='color:red;'>排序</span>

    排序

    2023-12-29 23:26:01      23 阅读
  3. media-ctl 生成拓扑和数据流图

    2023-12-29 23:26:01       66 阅读
  4. Golang time CST以及UTC介绍

    2023-12-29 23:26:01       25 阅读
  5. CST高频仿真的网格技术

    2023-12-29 23:26:01       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-29 23:26:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-29 23:26:01       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-29 23:26:01       82 阅读
  4. Python语言-面向对象

    2023-12-29 23:26:01       91 阅读

热门阅读

  1. uniapp-H5项目的坑

    2023-12-29 23:26:01       54 阅读
  2. Python爬虫实战演练之爬去VIP电影

    2023-12-29 23:26:01       57 阅读
  3. 大模型系列课程学习

    2023-12-29 23:26:01       51 阅读
  4. MySQL 设置商品乐观锁号示例

    2023-12-29 23:26:01       56 阅读
  5. 力扣:435. 无重叠区间(贪心)

    2023-12-29 23:26:01       54 阅读
  6. Leetcode的AC指南 —— 哈希法:454. 四数相加 II

    2023-12-29 23:26:01       70 阅读
  7. 配置LDAP 用户连接Oracle

    2023-12-29 23:26:01       62 阅读
  8. 算法笔记(模拟最大三数乘积问题)

    2023-12-29 23:26:01       59 阅读