使用stl sort函数的例子
struct
tagElem
{
int key;
int i;
}
;
bool
UDgreater (
struct
tagElem e1,
struct
tagElem e2 )
{
return e1.key > e2.key;
}

void
test()
{
struct tagElem node;
vector<struct tagElem> vp;
for(int i =0; i < 10; i++)
{
node.key= i + 100;
node.i =i;
vp.push_back(node);
}
sort(vp.begin(), vp.end(), UDgreater);
for(int i =0; i < 10; i++)
{
cout<< vp[i].point << endl;
}
}

浙公网安备 33010602011771号