C++学习笔记 32 排序

cppreference排序介绍

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

int main() {
	std::vector<int> values = { 7, 3, 6, 5, 1, 2 };

	//1. 默认正序排列
	std::sort(values.begin(), values.end());
	//2. 指定倒序排列
	std::sort(values.begin(), values.end(), std::greater<int>());
	//3. lambda自定义排序规则
	std::sort(values.begin(), values.end(), [](int a, int b) {
		return a > b;
	});

	for (int value : values)
		std::cout << value << std::endl;

	std::cin.get();
}
posted @ 2025-12-23 10:34  超轶绝尘  阅读(11)  评论(0)    收藏  举报