std::sort 的基本用法 std::sort 是 C++ 标准库中的一个高效排序算法,位于 <algorithm> 头文件中。它接受两个迭代器参数,表示排序范围的起始和结束位置。 #include <algorithm> #include <vector> std::vector<int> vec = {4, 2, 5, 3, 1}; std::sort(vec.begin(), vec.end()); 自定义比较函数 std::sort 允许通过提供自定义比较函数来实现不同的排序顺序。比较函数应返回布尔值,指示第一个参数是否应排在第二个...