Which container is STL?

I need a container (not necessarily an STL container) that allows me to do the following:

  • Insert and delete items at any position
  • Access items by their index
  • Iterate over items in any order

I used std :: list , but it will not allow me to insert any position (this happens, but for this I will have to iterate over all the elements, and then insert into the position I want, which is slow since the list can be huge). Can you recommend any effective solution?

+3
source share
10 answers

, " " - , , , ? !

, , , :

std::map [- , ]

  • , - O (log (n))

hash_map std::tr1::unordered_map [-]

  • , - () O (1)
  • ""
+7

, , .

+4

vector, deque. vector , deque .

+3

, , . , , .

, vector , ( ), (, ).

+1
+1

. - , , ( , , ) pop_back. ( , !?), push_back ( ) , .

+1

" ", , , , , ?

, . O (log (n)), O (log (n)) O (log (n)). O (n) . , , - , node.

:

0

, , , . , , node . . , , node. , , , node. node N, . , , N, , . , . , , node N. , A) node B), N .

0
source

Containers http://adrinael.net/containerchoice

But it looks like you are looking for one container with the following properties:

  • All the benefits of various containers
  • None of their subsequent flaws.

And that is not possible. One advantage is causing damage. Choosing a container is a compromise.

0
source

std :: vector

[padding for "15 characters" here]

-4
source

All Articles