<algorithm> 中sort的使用

来源:互联网 发布:hm怎么没有淘宝旗舰店 编辑:程序博客网 时间:2024/06/06 19:56
#include<iostream>#include<time.h>#include<algorithm>#include<cmath>using namespace std;#define N 10struct 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;}

原创粉丝点击