vector

Vecter is similar to Array. The only difference lies in the flexibility of the use of space. Array is static, vecter is dynamic.

operation

  • Definition:The vector < int > iv (2, 9);To define avectorThere are two elements in it2, 9.
  • empty(): Returns if it is emptytureIf not empty, returnfalse.
  • size(): Returns the number of container elements.
  • push_back(x): the elementxInsert the tail.
  • pop_back(): Pops the end element, but cannot be accessed, and returnsvoid.
  • front(): Look at the first element.
  • back(): Look at the last element.
  • erase(iterator position): Clears elements at a location.
  • insert(position,n,x)In:positionBefore insertingnax.

list

A list is not a continuous space and you cannot use [] like a vector.

operation

  • Definition:list<int> ilist;Define a linked list of positive types.
  • empty(): Returns if it is emptytureIf not empty, returnfalse.
  • size(): Returns the number of container elements.
  • front(): Look at the first element.
  • back(): Look at the last element.
  • push_back(x): the elementxInsert the tail.
  • pop_back(): Pops the end element, but cannot be accessed, and returnsvoid.
  • push_front(x): the elementxInsert the header.
  • pop_front(): pops the header element, but cannot be accessed. Returnsvoid.
  • insert(position,x)In:positionBefore insertingx.
  • remove(x)In:xAll elements are removed.
  • unique(x): Removes consecutive elements with the same value.

deque

A deque is a continuous linear space with bidirectional openings.

operation

  • Definition:A deque < int > ideq (20, 9);To define adequeAnd there are20a9;
  • empty(): Returns if it is emptytureIf not empty, returnfalse.
  • size(): Returns the number of container elements.
  • front(): Look at the first element.
  • back(): Look at the last element.
  • push_back(x): the elementxInsert the tail.
  • pop_back(): Pops the end element, but cannot be accessed, and returnsvoid.
  • push_front(x): the elementxInsert the header.
  • pop_front(): pops the header element, but cannot be accessed. Returnsvoid.
  • erase(iterator position): Clears elements at a location.
  • insert(position,x)In:positionBefore insertingx.

stack

A stack is a first-in, last-out container with a deque at the bottom, which can also be implemented with a list.

operation

  • Definition:stack<int> istack;Define a storeintthestack.
  • empty(): Returns if it is emptytureIf not empty, returnfalse.
  • size(): Returns the number of container elements.
  • top()Returns the element at the top of the stack.
  • pop(): Pops an element.
  • push(x): Presses an element.

slist

Slist is a bidirectional linked list. The operation is the same as list.

set

The set property is that all elements are automatically sorted by their key value. Elements of a set do not allow two elements to have the same key. The bottom layer is an RB_tree.

operation

  • Definition:set<int> iset(ia,ia+5); ``iaIt’s an array.
  • empty(): Returns if it is emptytureIf not empty, returnfalse.
  • size(): Returns the number of container elements.
  • count(x): Returns to the container,xNumber of elements.
  • insert(x): Insert elementsx.

map

All elements in the map are sorted by key, and all elements are pairs, where the first element is treated as a key and the second element as a real value. You can change the real value, but you can’t change the key.

operation

  • Definition:
map<string, int> simap{ {"jjhou",1}, {"jehou",1}, {"jahou",1}, }; // Use string as the key and int as the real value. pair<string, int> value(string("david"),5);Copy the code

-insert(value): inserts a pair value.

  • simap[a]: The key value isaThe value of the.

multset

The usage is exactly the same as set, except that it allows duplicate key values.

multmap

The usage is exactly the same as map, except that it allows duplicate key values.

Unorder_map and unorder_set

The usage is the same as before, except that the underlying implementation is not rb_tree but hashtable.

priority_queue

Build a queue and sort it according to the given criteria.

  • Definition:priority_queue<Type,Container,Functional>
  • empty(): Returns if it is emptytureIf not empty, returnfalse.
  • size(): Returns the number of container elements.
  • top(): Look at the first element.
  • push(x): the elementxInsert queue and sort.
  • pop(): pops the header element, but cannot be accessed. Returnsvoid.
  • emplace(x): Constructs an element in place and inserts the queue.
  • swap(): Exchange content