Container class overview

xiaoxiao2021-03-06  85

VECTOR

1). Random Access --- The time spent on the i-th element is constant, and is independent of I.

2). Varying length --- The length variable, the commonality of the STL container, manages memory by the library

3). AMORTIZED Constant Time Insertion and deleions at the end

--- That is, the time spent inserted or deleted at the end of the VECTOR is allocated to each case.

When inserted, a memory allocation problem is involved, setting Vector.Size () = n When its Capacity is also N, you need to redistribute the space when inserting data at the end, which involves data copy issues, usually reassigned spaces. Some strategy increases (such as a multiple of N), such as 2n, which is inserted from n-> 2n, just starting N data, and has not been copied in the future, only inserting the corresponding data into the Vector That is, the time is scheduled to be O (N / N), which is constant level.

2. Deque

With the vector, it is only a constant after the team's tail plugges. (Realization of cyclic queue?)

3. List

Take the time spent in the i-th element is related to n, inserted anywhere, the deletion time is constant.

4 set, map

It belongs to the sorted sociated container, the content inside is sorted.

转载请注明原文地址:https://www.9cbs.com/read-107345.html

New Post(0)