List 的排序,重载greater实现

#include

#include

#include

using namespace std;

typedef struct mystruct

{

int a;

int b;

}mystruct;


template<>

struct std::greater

{

bool operator()( mystruct X,  mystruct Y) const

{

return X.a  == Y.a ?  X.b < Y.b : X.a < Y.a;

}

};

void main()

{

list data;

srand((unsigned)time(NULL));

mystruct StrInfo;

for (int i =0; i < 10 ; i ++)

{

StrInfo.a = 1 + rand() % 10;

StrInfo.b = 1 + rand() % 10;

data.push_back(StrInfo);

}

data.sort(greater());

return;

}

你可能感兴趣的:(List 的排序,重载greater实现)