您的位置:首页 > 其它

对二维数组进行快速排序的 方法

2016-02-25 09:27 274 查看
解决问题 的方法 千千万 在这里我就写一种自己认为比较好的 排序思想吧 .

最初的时候 我想的是 这样的

#include<cstdio>
#include<algorithm>
using namespace std;
bool cmp(int a[],int b[])
{
return a[0]>b[0];
}
int main()
{
int a[3][2]={3,4,1,2,5,6};
sort(a,a+3,cmp);
}


然而 编译的时候 是有 错误的 可能 sort 无法传送二维数组

然而 有困难就一定有 克服困难的方法 当引入结构体的时候就注定了 这个问题可以简单的解决掉 .

#include<cstdio>
#include<algorithm>
using namespace std;
struct tm
{
int v[4];
};
bool cmp(tm a,tm b)
{
return a.v[3]<b.v[3];
}
int main()
{
tm m[1000];
sort(m,m+1000,cmp);
}


这个 二位数组排序 我感觉还是在 对字符进行排序比较好一点 因为有 strcmp函数的存在

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
string strin[3],temp;
strin[0]="a  s",strin[1]="bs";strin[2]="az";
strin[0]=strin[1]+strin[0];
//sort(strin,strin+3);                                // 神器  可以对二维数组 进行排序  而且 还可以 直接进行  赋值  和 加法 运算 . 666
strin[2]=strin[1];
cout<<strin[0]<<"********* "<<strin[2];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: