gpt4 book ai didi

c++ - 排序函数如何作用于一对整数对的 vector ?

转载 作者:行者123 更新时间:2023-11-30 03:30:27 24 4
gpt4 key购买 nike

给定

std::vector<std::pair<std::pair<int,int>, std::pair<int,int>> a;
std::sort(a.begin(),a.end());

std::sort 函数如何对这种类型的 vector 进行排序?对的进一步级联是否有任何概括?

最佳答案

  1. std::sort使用 operator<除非另有说明。
  2. 根据 std::pair 的文档:

http://en.cppreference.com/w/cpp/utility/pair/operator_cmp

比较运算符,例如<被定义为字典等价物:

Compares lhs and rhs lexicographically, that is, compares the first elements and only if they are equivalent, compares the second elements.

在您的情况下,此逻辑将在每个对级别递归应用。

关于c++ - 排序函数如何作用于一对整数对的 vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44982041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com