what is "comp" in your code?

On Wed, Aug 10, 2011 at 6:19 PM, aanchal goyal <goyal.aanch...@gmail.com>wrote:

> 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?
>
> #include<iostream>
> #include<algorithm>
> #include<vector>
>
> using namespace std;
>
>
> typedef struct
> {
>  int x;
>  int y;
> }point;
>
> struct comp_x
> {
>  bool operator()(point &a, point &b)
>       return a.x<b.x;
> }
>
> struct comp_y
> {
>  bool operator()(point &a, point &b)
>       return a.y<b.y;
> }
>
> int main()
> {
>  vector<point> vc;
>  int n;
>  cin>>n;
>  point a;
>
>  for(int i=0;i<n;i++)
>  {
>   cin>>a.x;
>   cin>>a.y;
>   vc.push_back(a);
>  }
>  cout<<endl;
>  sort(vc.begin(), vc.end(), comp);
>
>  for(int i=0;i<n;i++)
>  {
>   cout<<vc[i].x<<" "<<vc[i].y<<endl;
>  }
>
>  system("pause");
>  return 0;
> }
>
>
> --
> Regards,*
> Aanchal Goyal*.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to