對結構體排序,下面是對tree這個結構體根據其w的值做升序排序
struct tree{
int u,v,w;
}tr[range2];
bool cmp(const tree &x,const tree &y) //cmp是sort要用的排序規則
{
return x.w<y.w;
}
sort(tr,tr+k,cmp);
看到還有用operator<的方法
對結構體排序,下面是對tree這個結構體根據其w的值做升序排序
struct tree{
int u,v,w;
}tr[range2];
bool cmp(const tree &x,const tree &y) //cmp是sort要用的排序規則
{
return x.w<y.w;
}
sort(tr,tr+k,cmp);
看到還有用operator<的方法