I am in need of ordering a list of numbers stored in a C++ vector:
#include <vector>
#include <iostream>
#include <algorithm>
struct A
{
};
bool compare(A i1, A i2)
{
if(i1.vec.size() > i2.vec.size())
return true;;
}
int main()
{
std::vector<A> ax;
ax.emplace_back(A{ 100, 300, 6, 123, 12, 451, 552});
ax.emplace_back(A{ 100, 300, 6, 123, 12, 451});
std::sort(ax.begin(), ax.end(), compare);
return 0;
}
As per the above code the ordering of ax vector should be:
{ 100, 300, 6, 123, 12, 451}
{ 100, 300, 6, 123, 12, 451, 552}
I am unable to get what needs to be added in compare function to achieve it?