mutating algorithm Question 3

Last Updated :
Discuss
Comments

Complete the myCmp() function in the program to sort the array arr in descending order based in the y coordinate.

C++
#include <bits/stdc++.h>
using namespace std;
struct Point
{
    int x, y;
};
bool myCmp(Point p1, Point p2)
{
    // Missing code here
}
int main()
{
    Point arr[] = {{3, 10}, {2, 8}, {5, 4}};
    int n = sizeof(arr) / sizeof(arr[0]);
    sort(arr, arr + n, myCmp);
    return 0;
}


return (p1.y > p2.y);

return (p1.x < p2.x);

return (p1.y < p2.y);

return (p1.x > p2.x);

Share your thoughts in the comments