二维数组快速排序sort
- 1. 使用比较函数cmp
- 2. 使用lambda表达式
使用c++的快排函数需要包含头文件
#include<algorithm>
1. 使用比较函数cmp
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
bool cmp(vector<int>&a, vector<int>&b)
{
return a[0] > b[0];
}
void main()
{
vector<vector<int>> m_sort = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
sort(m_sort.begin(), m_sort.end(), cmp);
while (true)
{
}
}
2. 使用lambda表达式
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
void main()
{
vector<vector<int>> m_sort = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
sort(m_sort.begin(), m_sort.end(), [](vector<int>&a, vector<int>&b)
{
return a[0] > b[0];
});
while (true)
{
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)