Hi friends,
I recently came up with a question. Kindly tell me it’s solution. My question:
There are n points with co-ordinates (x1,y1), (x2,y2),…, (xn,yn). I want to sort these points based on the value of their x co-ordinates. Therefore I am using the sort function to sort the x co-ordinates, but am unable to access there respective y co-ordinates. Please tell me a way by which I can retrieve the corresponding y co-ordinates after sorting with the best efficiency.
struct vert
{
int xcord,ycord;
};
bool cmp (vert a,vert b) //two objects a&b of type vert(struct)
{
return a.xcord<b.xcord;//sorting structs based on xcord
}
//in main function
vert v[n];//assume n pts are there
sort(v,v+n,cmp);
@a1a99_3 I carried out your answer and am getting the desired answer. Thanks! However, can you kindly tell me why/how is the ‘cmp’ function sorting the structure based on the xcord and how is it being carried out in the sort function.Thanks onc e again!
@anupam_datta……Didn’t I explain it to you a billion times in school!!!
And HOW DO YOU carry out AN !?Answer?! and get the “DESIRED” !?Answer?!..LOL
(CaRrY oUt???)
I am the one who liked ur SILLY comment and am very sure that I’ll remain to ONLY one to do so…HA HA HA!!!