dimanche 27 novembre 2016

Evaluation of the binary predicates C++

How are the binary predicates evaluated?

For example, if I want to sort in the descending order, then should I write:

bool isGreater(int x, int y) 
{
    return x > y;
}

or

bool isGreater(int x, int y) 
{
    return y > x;
}

What exactly is the difference between the two? I understand that the two parameters would be compared to each other, but what should the return result be - true or false? And how does it matter?

The sort() function would be called in this fashion (height is the array to be sorted):

sort(height, height+N, isGreater);

Note: I did refer links like this one and this one, but they don't explicitly focus on this problem.

Could someone please clarify my doubt? Thanks!

Aucun commentaire:

Enregistrer un commentaire