4
不C++的std ::列表排序功能是保证保护列表中的相同元素的顺序?例如。如果我们在列表中有对象A,B和C,并且比较运算符被重载以至于A == C和B,我们是否必须得到B-A-C或者是否有可能得到B-C-A?
不C++的std ::列表排序功能是保证保护列表中的相同元素的顺序?例如。如果我们在列表中有对象A,B和C,并且比较运算符被重载以至于A == C和B,我们是否必须得到B-A-C或者是否有可能得到B-C-A?
是的,在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.
是的,标准要求list :: sort要稳定。
检查http://stackoverflow.com/questions/1100561/stable- sort-a-stl-list-in-c。 – a1ex07 2011-03-03 20:02:30