中sort的使用

#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;
}

你可能感兴趣的:( 中sort的使用)