Doubt in comparators

I’m not getting how comparators work. Like here we are retuning p1.first < p2.first and d1 < d2. What they mean and how they the coordinates are getting sorted?

Request you to please elaborate.

hello @gambhirrahul0
sorting is simply rearranging the elements. it means deciding which elements comes first between each pair of element(like you do swap/non swap in bubble sort).
so the logic is,
consider the compare function as
bool compare(int a, int b){
// returning true means: a will be placed before b in new arrangement
//returning false means : b will come before a in new arrangement
}
so

  1. return a<b : will return true when a is less than b, means a comes first when a <b… this is ascending order.
  2. return a>b: will return true when a is greater than b, means a comes first when a>b… this is descending order.

@gambhirrahul0

why u have reopend this after so long ?

It was done by mistake, sorry. I’m closing it

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.