Sorting array of structs

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.

Can someone help me please?
For example,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)
        return true;
    if (a.a > b.a)
        return false;

    if (a.b < b.b)
        return true;
    if (a.b > b.b)
        return false;

    if (a.c < b.c)
        return true;
    if (a.c > b.c)
        return false;

    return false;
}

//...

std::sort(array, array + length, criterium);
Topic archived. No new replies allowed.