Is the std::set iteration order always ascending according to the C++ specification?

前端 未结 5 825
遥遥无期
遥遥无期 2020-12-05 06:42

Here http://www.cplusplus.com/reference/stl/set/ I read that std::set in C++ is \"typically\" implemented as a tree (red-black one?) and it is sorted.

I could not un

5条回答
  •  星月不相逢
    2020-12-05 07:22

    Per the C++ standard, iteration over the elements in an std::set proceeds in sorted order as determined by std::less or by the optional comparison predicate template argument.

    (Also per the C++ standard, insertion, lookup and deletion take at most O(lg n) time, so balanced search trees are currently the only viable implementation choice for std::set, even though the use of red-black trees is not mandated by the standard.)

提交回复
热议问题