[algogeeks] STL sort

2011-08-10 Thread aanchal goyal
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

Re: [algogeeks] STL sort

2011-08-10 Thread Nitin Nizhawan
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

Re: [algogeeks] STL sort

2011-08-10 Thread aanchal goyal
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

Re: [algogeeks] STL sort

2011-08-10 Thread aanchal goyal
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

Re: [algogeeks] STL sort

2011-08-10 Thread Nitin Nizhawan
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){

Re: [algogeeks] STL sort

2011-08-10 Thread Amol Sharma
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){