In C++, is the amortized complexity of std::string::push_back() O(1)?

孤街醉人 提交于 2019-12-21 17:06:19

问题


I know the standard specifies that it is for vectors, but what about strings?


回答1:


Yes, it is amortized constant time. See table 101 on page 716 of this document:

Table 101 lists operations that are provided for some types of sequence containers but not others. An implementation shall provide these operations for all container types shown in the “container” column, and shall implement them so as to take amortized constant time.

Operation      | Description          | Container
---------------+----------------------+----------------------------------
a.push_back(t) | Appends a copy of t. | basic_string, deque, list, vector


来源:https://stackoverflow.com/questions/13892989/in-c-is-the-amortized-complexity-of-stdstringpush-back-o1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!