stl list - complexity

后端 未结 5 2286
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 22:19

Are all the inserts (anywhere) for the list constant?

What about access?

Front, back - constant time?

and in the middle of the list - linear time?

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 23:19

    Inserts anywhere in a std::list are constant time operations.

    That said, before you can insert, you need to get an iterator to the location you'd like to insert to, which is a linear time operation unless you're talking about the front or back.

提交回复
热议问题