I need an algorithm that sorts an array of structs first by one component, and then, if this one repeats itself (ex: 1 2 3 3 4), unless a second component is equal to 0, it sorts the array by a third, and then a fourth component in the struct.
struct A{
int a, b, c;
};
//Returns true if a has a sort order lower than b's, i.e. if { b, a } is unsorted.
bool criterium(const A &a, const A &b){
if (a.a < b.a)
returntrue;
if (a.a > b.a)
returnfalse;
if (a.b < b.b)
returntrue;
if (a.b > b.b)
returnfalse;
if (a.c < b.c)
returntrue;
if (a.c > b.c)
returnfalse;
returnfalse;
}
//...
std::sort(array, array + length, criterium);