STL中对自定义数据类型的快速排序
#include <iostream>
#include <algorithm>
using namespace std;
struct abc
{
int begin,end,length; //own struct
};
abc a[100]; //set the new struct
int n,i;
bool cmp(abc x,abc y)//the function to show the way to sort
{
return x.length<y.length;//sort from small int to big int
}
int main()
{
cin>>n;
for(i=0;i<n;i++)
cin>>a[i].begin>>a[i].end>>a[i].length;
sort(a,a+n,cmp);//sort(vector's name,vector's name+size,name of the function);
for(i=0;i<n;i++)
cout<<a[i].begin<<' '<<a[i].end<<' '<<a[i].length<<endl;
return 0;
}