Let's take your line that does the comparison:
Code:
array[d] > array[d+1]
and convert it to a function since you said these would actually be structs:
Code:
compare(&array[d], &array[d+1]) > 0
Inside that function, you should implement the correct way to compare those two elements so that member "a" takes precedence over member "b", like this:
Code:
int compare(const myStruct* e1, const myStruct* e2)
{
// if e1->a > e2->a, return 1
// if e1->a < e2->a, return -1
// if e1->b > e2->b, return 1
// if e1->b < e2->b, return -1
// Return 0 to signal "equality"
}