c++對結構體排序(仿函數)



結構體中按照第一個元素進行排序

 比如:

op compareGreater;

 sort(regionA.begin(),regionA.end(),compareGreater);

 sort(regionB.begin(),regionB.end(),compareGreater);

merge(regionA.begin(),regionA.end(),regionB.begin(),regionB.end(),tempVector.begin(),compareGreater);

 

struct abc<span style="font-family: Arial, Helvetica, sans-serif;">{</span>
 <span style="white-space:pre">	</span>int a;
 <span style="white-space:pre">	</span>double b;
 <span style="white-space:pre">	</span>int c;
};
class op{
public:
 bool operator()(abc a,abc b){
  if (a.a>b.a)
  {
   return true;
  }
  else
{
   return false;
  }
 }
};
struct abc<span style="font-family: Arial, Helvetica, sans-serif;">{</span>
 <span style="white-space:pre">	</span>int a;
 <span style="white-space:pre">	</span>double b;
 <span style="white-space:pre">	</span>int c;
};
class op{
public:
 bool operator()(abc a,abc b){
  if (a.a>b.a)
  {
   return true;
  }
  else
{
   return false;
  }
 }
};
發佈了41 篇原創文章 · 獲贊 2 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章