Unable to understand Comparator function behaviour when sorting an array of 1000 elements with value 1000000 in descending order. (The array is 1 indexed)
The first instance of definition of comparator function has random zeroes at some indexes in the array.
The second instance of definition of comparator function works fine. Could anyone explain why this is happening
bool func(long long a, long long b){
return (a >= b);
}
sort (A+1, A + 1000 + 1, func);
bool func(long long a, long long b){
return (a > b);
}
sort (A+1, A + 1000 + 1, func);
Output 1: 1000000 1000000 1000000 0 0 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000
Output 2: 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000
>=doesn't satisfy strict weak ordering requirements, it leads to UB.b < ain your former code.