結構體二級排序

sort函數對結構體排序,如果結點a相等,比較結點b ,以從小到大 爲例: struct node{ int num; int data; }c[100]; 對於上述定義的結構體可以添加一個自定義cmp函數來實現結構體的排序: 寫法1: bool cmp(node a,node b) { if(a.t!=b.t) return a.t<b.t; else return a.s<b.s; }
相關文章
相關標籤/搜索