I am in need of ordering a list of numbers stored in a C++ vector:
#include <vector>
#include <iostream>
struct Oid
{
Oid(std::vector<oid_data_unit> _oid_) : mOid(_oid_) {}
Oid(std::initializer_list<oid_data_unit> _oid_) : mOid(_oid_) {}
std::vector<oid_data_unit> mOid;
};
bool compare(Oid i1, Oid i2)
{
if(i1.size() > i2.size())
return true;;
}
int main()
{
Oid e({ 1, 3, 6, 1, 2, 1, 2,2,1, 4 })
Oid c({ 1, 3, 6, 1, 2, 1, 2, 2, 3 });
Oid b({ 1, 3, 6, 1, 2, 1, 2, 1, 0 });
Oid a({ 1, 3, 6, 1, 2, 1, 2 });
Oid d({ 1, 3, 6, 1, 2, 1, 2,2,1, 3 });
std::vector<Oid> ax;
ax.emplace_back(a);
ax.emplace_back(b);
ax.emplace_back(c);
ax.emplace_back(d);
ax.emplace_back(e);
std::sort(ax.begin(), ax.end(), compare);
return 0;
}
As per the above code the ordering of ax vector should be:
({ 1, 3, 6, 1, 2, 1, 2 })
({ 1, 3, 6, 1, 2, 1, 2, 1, 0 });
({ 1, 3, 6, 1, 2, 1, 2, 2, 3 });
({ 1, 3, 6, 1, 2, 1, 2,2,1, 3 });
({ 1, 3, 6, 1, 2, 1, 2,2,1, 4 });
I am unable to get what needs to be added in compare function to achieve it?
Aucun commentaire:
Enregistrer un commentaire