
On Fri, 3 Jun 2005, Filippos Papadopoulos wrote:
Hi.
In my program i am trying to sort a deque using STL sort algorithm:
deque<double> q;
/* fill q with some doubles*/ ... /* sort */ sort(q.begin(), q.end());
The above works OK.
The problem is that now i want to have the following deque:
struct rrTask { double C; int tid; }; deque<rrTask> q;
/* fill q with some rrTasks*/ rrTask rt; rt.C = A_DOUBLE; rt.tid = AN_INT; q.push_back(rt);
/* Try to sort q !!!*/ sort(q.begin(), q.end(), rt.C);
The above seems to be wrong. My intention is to sort q using rt.C field as the sort key. What is the right (and easiest) way to do this?
Thanks.
Replying to my email. I think i found the solution: I modified rrTask like this class rrTask { public: double C; int tid; bool operator() (const rrTask& x, const rrTask& y) const { return (x.C < y.C); } bool operator() (const rrTask& x, const double& _C) const { return (x.C < _C); } }; And now i call sort like this: sort(qs.begin(), qs.end(), rrTask()); Also i call lower_bound with rrTask() as the comperator.