I have a vector of stuct, how to sort this vector?
problem is I can't overload the '' operator in struct definition, as i want
to sort by 'x' one time, and then by 'y'. I tried to write the comparator
function separatley but its no working. How to do it?
#includeiostream
#includealgorithm
what is comp in your code?
On Wed, Aug 10, 2011 at 6:19 PM, aanchal goyal goyal.aanch...@gmail.comwrote:
I have a vector of stuct, how to sort this vector?
problem is I can't overload the '' operator in struct definition, as i
want to sort by 'x' one time, and then by 'y'. I tried to write
sorry, comp is either comp_x or comp_y
On Wed, Aug 10, 2011 at 6:24 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote:
what is comp in your code?
On Wed, Aug 10, 2011 at 6:19 PM, aanchal goyal
goyal.aanch...@gmail.comwrote:
I have a vector of stuct, how to sort this vector?
problem is I
got it.
On Wed, Aug 10, 2011 at 6:31 PM, aanchal goyal goyal.aanch...@gmail.comwrote:
sorry, comp is either comp_x or comp_y
On Wed, Aug 10, 2011 at 6:24 PM, Nitin Nizhawan
nitin.nizha...@gmail.comwrote:
what is comp in your code?
On Wed, Aug 10, 2011 at 6:19 PM, aanchal goyal
bool operator()(point a, point b){
return a.xb.x;
}
remove references it should work. following is working code.
#includeiostream
#includealgorithm
#includevector
using namespace std;
typedef struct
{
int x;
int y;
}point;
struct comp_x
{
bool operator()(point a, point b){
instead of struct you can use *pairint,int* which will make the work
easier for you
--
Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
On Wed, Aug 10, 2011 at 6:47 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote:
bool operator()(point a, point b){