Fix compare functions used by std::sort
In commit 3306cb3e (Nov 22, 2016), the obsolete qSort function
was replaced by std::sort.
However, there is a subtile difference: qSort was able to
cope with non-strict weak ordering given back by the compare
function, whereas std::sort is not, possibly resulting in
out-of-bound accesses and crashes.
In a previous commit 2856bba6, a compare function in treemap.cpp
was fixed, but we missed fixing a few other compare functions which
now are used by std::sort.
This fixes bug 385127.