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

前端 未结 5 819
遥遥无期
遥遥无期 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:20

    by specification iteration order of set is always ascending

    Yes, the values of set are always ascending if you print them out in sequence. As the description says, it's typically implemented using Red-Black Tree(RBT), but the compiler writers have the option to violate this, but usually the would stick to the Theme of RBT since any other implementation won't be resource efficient to achieve the task of set.

提交回复
热议问题