Why does this code is RTE ?!
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Name |
---|
Your comparison function is incorrect. For example it returns
true
for 0 and 0 which should never happen for correctless than
comparison.That's true but what's the problem ? If two equal values are swapped in the array it will cauz no effect.
Well first of all, even this is already enough according to C++ standard to lead to undefined behaviour so you can't expect anything after doing sort like that. But in reality I think your comparison function acts very weird in other cases too, like:
I don't think it can be well defined what sort should do in this case.
C++ assumes that your comparator is strict "less than" operator, not the "less than or equal to". So the followings must be satisfied, otherwise you'll get weird result.
1) if func(a, b) is true, then func(b, a) must be false 2) if func(a, b) and func(b, c) is true, then func(a, c) must be true 3) func(a, a) must be false