why is less<T> comparator used for max heap and greater<T> for min heap?

Viewed 182

Shouldn't it be the opposite? what do we mean by less and greater in detail when we use them as comparators I don't understand the complete explanation for this, could someone please help me out.

1 Answers

It is purley a matter of convention to use the comparator to decide whether one element a comes before another element b. Thats why for increasing order a < b or std::less is used and for decreasing order a > b / std::greater.

If the convention was the opposite: Use the comparater to decide which element comes last. Then < would result in decreasing order and > would result in increasing order.

Related