如何用sort()对结构体进行排序:
如:
#include <list>
using namespace std;
typedef struct TaskTable {
int ID;
int sum;
CTime curTime;
} TaskTableType;
typedef list<TaskTableType> TaskQueue;
TaskQueue curQ;
我想通过void sort(RanIt first, RanIt last, Pred pr);比较结构体中的ID的大小来对curQ进行排序。但不知道比较函数怎么写!请较大虾!如何使用?最好能保我写个例程!
谢谢先~~
如:
#include <list>
using namespace std;
typedef struct TaskTable {
int ID;
int sum;
CTime curTime;
} TaskTableType;
typedef list<TaskTableType> TaskQueue;
TaskQueue curQ;
我想通过void sort(RanIt first, RanIt last, Pred pr);比较结构体中的ID的大小来对curQ进行排序。但不知道比较函数怎么写!请较大虾!如何使用?最好能保我写个例程!
谢谢先~~
int ID;
int sum;
CTime curTime;
} TaskTableType;
typedef vector<TaskTableType> TaskQueue;
class SortFunctor
{
public:
bool operator()(const TaskTable& r1,const TaskTable r2) const
{
return r1.ID>r2.ID; //just a test
};
};
TaskQueue m_DataList;
sort(m_DataList.begin(),m_DataList.end(),SortFunctor());