二维数组排序 sort
来源:互联网 发布:党员干部必知的新词 编辑:程序博客网 时间:2024/06/05 02:24
#include <iostream>
#include <algorithm>
#include <ctime>
using namespace std;
bool cmp(int *p, int *q)
{
if (p[0] == q[0])
{
if (p[1] == q[1])
{
return p[2]<q[2];
}
else return p[1]<q[1];
}
else return p[0]<q[0];
}
int main()
{
srand(time(0));
int b[10] = {3, 2, 1, 4, 5, 5, 7, 8, 9, 10};
int c[10] = {3,10,9, 4, 88, 6, 7, 8, 9, 11 };
int i;
int **a = new int*[10];
for (i = 0; i<10; ++i)
{
a[i] = new int[2];
a[i][0] = b[i];
a[i][1] = c[i];
//a[i][2] = rand() % 100;
//printf("%d\\t%d\\t%d",a[i][0],a[i][1],a[i][2]);
}
sort(a, a + 10, cmp);
//sort(a, a + 10);
cout<<"After sort"<<endl;
for(i=0;i<10;++i)
{
printf("%d %d\n",a[i][0],a[i][1]);
}
system("pause");
return 0;
}
#include <algorithm>
#include <ctime>
using namespace std;
bool cmp(int *p, int *q)
{
if (p[0] == q[0])
{
if (p[1] == q[1])
{
return p[2]<q[2];
}
else return p[1]<q[1];
}
else return p[0]<q[0];
}
int main()
{
srand(time(0));
int b[10] = {3, 2, 1, 4, 5, 5, 7, 8, 9, 10};
int c[10] = {3,10,9, 4, 88, 6, 7, 8, 9, 11 };
int i;
int **a = new int*[10];
for (i = 0; i<10; ++i)
{
a[i] = new int[2];
a[i][0] = b[i];
a[i][1] = c[i];
//a[i][2] = rand() % 100;
//printf("%d\\t%d\\t%d",a[i][0],a[i][1],a[i][2]);
}
sort(a, a + 10, cmp);
//sort(a, a + 10);
cout<<"After sort"<<endl;
for(i=0;i<10;++i)
{
printf("%d %d\n",a[i][0],a[i][1]);
}
system("pause");
return 0;
}
0 0
- 二维数组排序 sort
- C++ 二维数组sort排序
- Matlab 用sort函数排序 二维数组
- Matlab 用sort函数排序 二维数组
- sort对二维字符数组排序
- js sort 二维数组排序用法
- 用sort对二维数组排序
- Matlab 用sort函数排序 二维数组
- 1214 1159,二维字符数组sort排序
- sort对二维数组进行排序备忘
- sort对二维char数组排序?
- sort对二维字符数组排序
- JavaScript中用sort方法进行二维数组排序
- 数组,二维数组排序
- 数组排序。Sort
- 数组排序Arrays.sort
- js sort 数组排序
- Arrays.sort数组排序
- Multiply Strings
- 利用IIS服务发布网站
- 我的wine中文字体配置笔记
- if else与三目运算符的区别
- iOS 获取网络图片的大小
- 二维数组排序 sort
- ACM--字母序列--HDOJ 1020--Encoding--字符串
- CF Round #361 (Div. 2) 689C. Mike and Chocolate Thieves
- Adb connection Error:远程主机强迫关闭了一个现有的连接
- 【2013国家队互测】家族(family)
- 菜鸟's problem
- 在android中如何用线程来更新UI
- Spring security防止跨站请求伪造(CSRF防护)
- web.py – xml模版