mutating algorithm Question 4

Last Updated :
Discuss
Comments

What will be the output of the given program?

C++
#include <bits/stdc++.h>
using namespace std;
struct Point
{
    int x, y;
    bool operator<(Point &oth)
    {
        return this->y > oth.y;
    }
};
int main()
{
    Point arr[] = {{3, 10}, {2, 8}, {5, 4}};
    int n = sizeof(arr) / sizeof(arr[0]);
    sort(arr, arr + n);
    for (auto i : arr)
    {
        cout << i.x << " " << i.y << endl;
    }
    return 0;
}


5 4
2 8
3 10

3 10
2 8
5 4

2 8
3 10
5 4

3 10
5 4
2 8

Share your thoughts in the comments