Ale*_*lme 5 c++ sorting stdlist
C++ std :: list sort函数是否保证保留列表中相等元素的顺序?例如,如果我们在列表中有对象A,B和C并且比较运算符被重载,那么A == C和B <A,我们是否必须获得BAC或者是否可以获得BCA?
Cub*_*bbi 12
是的,在C++中list::sort()是稳定的,符合ISO 14882:2003 23.2.2.4 [lib.list.ops]/31
Effects: Sorts the list according to the operator< or a Compare function object.
Notes: Stable: the relative order of the equivalent elements is preserved.
If an exception is thrown the order of the elements in the list is indeterminate.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
785 次 |
| 最近记录: |