sort()

 
struct node  
{  
    int l;  
    int w;  
    bool visited;  
};

int cmp( const int &a, const int &b ){ //单关键字, 降序排序
    if( a > b )
       return 1;
    else
       return 0;
}

bool cmp(const node &a, const node &b)//双关键字 ,先按l升序排序,如果l相同,则按w升序排序。

   
if(a.l!=b.l) 
    { 
       
return a.l<b.l; 
    } 
   
else 
    { 
       
return a.w<b.w; 
    } 

sort(wood, wood
+n, cmp); 

原文地址:https://www.cnblogs.com/richardcpp/p/2735233.html