• <i id='Uyr4F'><tr id='Uyr4F'><dt id='Uyr4F'><q id='Uyr4F'><span id='Uyr4F'><b id='Uyr4F'><form id='Uyr4F'><ins id='Uyr4F'></ins><ul id='Uyr4F'></ul><sub id='Uyr4F'></sub></form><legend id='Uyr4F'></legend><bdo id='Uyr4F'><pre id='Uyr4F'><center id='Uyr4F'></center></pre></bdo></b><th id='Uyr4F'></th></span></q></dt></tr></i><div id='Uyr4F'><tfoot id='Uyr4F'></tfoot><dl id='Uyr4F'><fieldset id='Uyr4F'></fieldset></dl></div>
    1. <legend id='Uyr4F'><style id='Uyr4F'><dir id='Uyr4F'><q id='Uyr4F'></q></dir></style></legend>

        <small id='Uyr4F'></small><noframes id='Uyr4F'>

        <tfoot id='Uyr4F'></tfoot>

          <bdo id='Uyr4F'></bdo><ul id='Uyr4F'></ul>
      1. 在 C++ 中,按第一个元素然后按第二个元素对成对向量进行排序?

        Sort a vector of pairs by first element then by second element of the pair in C++?(在 C++ 中,按第一个元素然后按第二个元素对成对向量进行排序?)
        <legend id='6wZsE'><style id='6wZsE'><dir id='6wZsE'><q id='6wZsE'></q></dir></style></legend>

        <i id='6wZsE'><tr id='6wZsE'><dt id='6wZsE'><q id='6wZsE'><span id='6wZsE'><b id='6wZsE'><form id='6wZsE'><ins id='6wZsE'></ins><ul id='6wZsE'></ul><sub id='6wZsE'></sub></form><legend id='6wZsE'></legend><bdo id='6wZsE'><pre id='6wZsE'><center id='6wZsE'></center></pre></bdo></b><th id='6wZsE'></th></span></q></dt></tr></i><div id='6wZsE'><tfoot id='6wZsE'></tfoot><dl id='6wZsE'><fieldset id='6wZsE'></fieldset></dl></div>

            <small id='6wZsE'></small><noframes id='6wZsE'>

              <tbody id='6wZsE'></tbody>
              <bdo id='6wZsE'></bdo><ul id='6wZsE'></ul>

                1. <tfoot id='6wZsE'></tfoot>
                  本文介绍了在 C++ 中,按第一个元素然后按第二个元素对成对向量进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我有一个 vector> 数据类型,如果第一个元素相等,按对的第一个元素排序,然后按第二个元素排序的可接受方法是什么?例如可能 (1,10), (3,3), (7,13), (7,16), (8,1), (8,2), (15,2) 等

                  If I have a vector<pair<int,int> > datatype, what is the accepted way to sort it by the first element of the pair and then by second if the firsts are equal? For instance maybe (1,10), (3,3), (7,13), (7,16), (8,1), (8,2), (15,2) etc.

                  推荐答案

                  pairs 默认按第一个元素比较,然后是第二个.因此,如果您不关心在第一个元素比较相等时保留顺序,那么您可以使用 std::sort:

                  pairs by default compare by first element, then second. So, if you don't care about preserving the order when the first elements compare equal, then you can just use std::sort:

                  std::sort(v.begin(), v.end());
                  

                  这篇关于在 C++ 中,按第一个元素然后按第二个元素对成对向量进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)

                      <tbody id='XuUkO'></tbody>
                      <tfoot id='XuUkO'></tfoot>
                      <i id='XuUkO'><tr id='XuUkO'><dt id='XuUkO'><q id='XuUkO'><span id='XuUkO'><b id='XuUkO'><form id='XuUkO'><ins id='XuUkO'></ins><ul id='XuUkO'></ul><sub id='XuUkO'></sub></form><legend id='XuUkO'></legend><bdo id='XuUkO'><pre id='XuUkO'><center id='XuUkO'></center></pre></bdo></b><th id='XuUkO'></th></span></q></dt></tr></i><div id='XuUkO'><tfoot id='XuUkO'></tfoot><dl id='XuUkO'><fieldset id='XuUkO'></fieldset></dl></div>
                        <bdo id='XuUkO'></bdo><ul id='XuUkO'></ul>

                          <small id='XuUkO'></small><noframes id='XuUkO'>

                          1. <legend id='XuUkO'><style id='XuUkO'><dir id='XuUkO'><q id='XuUkO'></q></dir></style></legend>