使用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;
    }

}
posted on 2007-06-25 16:34  zdleek  阅读(9)  评论(0)    收藏  举报  来源