About STL containers and algorithms (a) container

STL containers

STL container comprises sequential container and associated containers .

  • Sequential containers

    Sequential container comprising: a dynamic array Vector variable length, the deque deque, doubly linked list List, queue Queue, Queue The priority_queue limited, and so it stack stack, the following features:

    • vector: a dynamic array, from the end of the fast insertion and deletion, direct access to any element.
    • list: doubly linked list, quickly insert and remove it from anywhere.
    • deque: deque, quickly insert and remove it from the front or rear, direct access to any element.
    • queue: queue, FIFO.
    • priority_queue: priority queue, the highest priority element is always the first out of the column.
    • stack: stack after backward out.

    They are called sequential containers, because the position of the element in the container regardless of the value of the same element, i.e. the container is not sorted. When the element is inserted into the container, designated in what position (tail, head or somewhere in the middle) is inserted, the element will be located in what position.

  • Associative containers

    Associated container includes set, multiset, map, multimap like.

    • set: collection, to quickly find, does not allow duplicate values.
    • multist: Quick Search, to allow duplicate values.
    • map: many mapping, based on keywords to quickly find, does not allow duplicate values.
    • multimap: many mapping, based on keywords to quickly find, duplicate values ​​are allowed.

Any two container object, as long as they have the same type, can be used <, <=,>,> =, ==,! = Compare operation. For example, suppose a, b are the same type of two container objects, follows these rules:

  • a == b: if the number of elements a and b are the same, and the corresponding elements are equal, then a == b is true, otherwise the value is false. Determining whether the element is equal with == operator.
  • a <b: sequentially comparing, if b is less than a determination of elements in the establishment, or a is greater than b, where each element the corresponding element of the establishment, is true, otherwise false.
  • a = b:! equivalent to (a == b)!.
  • a> b: equivalent to b <a.
  • a <= b: equivalent to (b <a)!.
  • a> = b: equivalent to (a <b)!.

All containers have two member functions:

  • int size (): returns the number of elements in the container object.
  • bool empty (): determines whether the container object is empty.

Order container and associated container has the following member functions:

  • begin (): returns a pointer to the first element iterator container.
  • end (): returns a pointer to the iterator's position after the last element of the container.
  • rbegin (): returns a pointer to the iterator vessel reverse the last element.
  • rend (): returns a pointer to the iterator reverse preceding the first element in the container position.
  • erase (...): remove one or several elements from the container. This more complicated function parameter is omitted here.
  • clear (): remove all elements from the container.

If a container is empty, then begin () and end () return values ​​are equal, rbegin () and rend () return value are equal.

Order container has the following common member functions:

  • front (): returns the first element of the vessel reference.
  • back (): returns the reference container of the last element.
  • push_back (): add new elements to the end of the container.
  • pop_back (): Delete the end of the container elements.
  • insert (...): inserting one or more elements.

Content from "Getting to advanced algorithms," Luo Yongjun, Guo Weibin version of the 2019
C language Chinese container network --STL introduction

Published 16 original articles · won praise 75 · views 20000 +

Guess you like

Origin blog.csdn.net/diviner_s/article/details/104195945