Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C++;? 我想知道如何用C++来根据第一列排序三重以下? 我可以使用std::map吗 0 0 1 1 2 0 2 0 3 0 1 4_C++_Sorting_Stl - Fatal编程技术网

如何在C++;? 我想知道如何用C++来根据第一列排序三重以下? 我可以使用std::map吗 0 0 1 1 2 0 2 0 3 0 1 4

如何在C++;? 我想知道如何用C++来根据第一列排序三重以下? 我可以使用std::map吗 0 0 1 1 2 0 2 0 3 0 1 4,c++,sorting,stl,C++,Sorting,Stl,想要的结果是 0 0 1 0 1 4 1 2 0 2 0 3 例如,您可以在std::tuple的向量上使用std::sort-默认比较是字典式的,因此第一列最重要。假设您对std::vector进行排序 C++11: std::sort(begin(vec), end(vec), [](const std::vector<int>& a, const std::vector<int>&

想要的结果是

0 0 1
0 1 4
1 2 0
2 0 3

例如,您可以在std::tuple的向量上使用std::sort-默认比较是字典式的,因此第一列最重要。

假设您对std::vector进行排序

C++11:

std::sort(begin(vec), end(vec), [](const std::vector<int>& a,
                                   const std::vector<int>& b){
  return a[0] < b[0]; // sorting on the first column only
});

数据最初是如何存储的?例如,如果不是203而是112,会发生什么?其他列的顺序是重要的还是可以有001、014、120、112?@xunzhang加载文件需要帮助还是只需要“如何排序”?如果
a[0]
b[0]
是相同的?@Zeda他没有,他使用的是
tuple
他也不想在第二个字段排序好,同意,OP只要求按第一列排序。我的错。@KonradRudolph从OP的问题来看,不清楚他们是否需要字典顺序,或者保留相对顺序是否足够好。@KonradRudolph没有任何迹象表明OP需要字典顺序:他说“根据第一列对下面的三元组进行排序”。
std::sort(begin(vec), end(vec));