您的位置:首页 > 编程语言 > Go语言

<algorithm> 中sort的使用

2013-04-15 11:01 288 查看
#include<iostream>
#include<time.h>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 10
struct position
{
int high;
int low;
};
bool operator <(position &a,position &b)
{
return a.low<b.low;
}
bool operator ==(position &a,position &b)
{
return (a.low==b.low)&&(a.high==b.high);
}
int main()
{
position temp[100];
int i;
srand((unsigned )time(NULL));
for (i=0;i<N;i++)
{
temp[i].low=rand()%10;
temp[i].high=rand()%10;
}
for (i=0;i<N;i++)
{
cout<<temp[i].low <<" "<<temp[i].high<<endl;
}
cout<<endl;
sort(temp,temp+N);
for (i=0;i<N;i++)
{
cout<<temp[i].low <<" "<<temp[i].high<<endl;
}
cout<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: