How to sort this vector of pair in such a way that it is stored in the following patter :-

Input is vector of pair
Input :- { {8,0} , {4,0} , {2,0} , {1,0} , {0,32} , {0,16} , {0,8} , {0,4} ,{0,2} ,{0,1} }

Output :- { {0,32} , {0,16} , {0,8} , {0,4} , {0,2} , {0,1} , {8,0} , {4,0} , {2,0} , {1,0} }

Keeping first priority as descending order of pair.second.
keeping second priority as descending order of pair.first.

Bro please use sort comparator function.

1 Like

How to do it can show the code ???

vector<int> v = {1,5,2,4,3};
bool f(int a, int b)
{
    return a>b;
}

in your main:
sort(v.begin(),v.end(),f);
//put the function name as the third argument without brackets

or

sort(v.begin(),v.end(),[](auto a, auto b){return a>b;})
//where the third argument is a lambda  

If you want the element a to be in front of element b return true.