The types of sequential containers are: vector,list, deque
Sequential container adapters:
Stack//Advanced post-stack
Queue//FIFO queues
Priority_queue//Priority queue at priority management level
1. Header files
#include <vector> <list><deque> // Each header file corresponds to a sequential container # Include <queue> // header file for queue priority Queue #include <stack> // Stack header file
2. Definition
vector<int>v; List<string> l; Deque<struct node>dq; // container type < container saved data type > container name;
3. Initialize (take vector type for example)
vector<t>v1; // to create an empty container Vector<t>v2 (n,i); // Create a vector container which consists of n values of element Vector<t>v3 (v2); // Create a V3 that is a copy of the V2 vector<t>v4 (n); // creates an n copy of an element that has initialization VECTOR<T>V5 (V2.begin (), V2.end ()-1); // Create an V5 value as an intermediate value for the index
Note: When initializing, values cannot be initialized between different types of containers
Note the definition of a container when there is a special case look at the following code "
vector< vector<int> >v3; // OK vector<vector<int> >v4; // OK vector<vector<int>>v5; // Error
When we write, we suggest using the first form of writing to develop a good habit.
In fact, the third kind of definition is not because it is written together with a > symbol that will synthesize a >> symbol
4. Operation of Iterators
Operations supported by all iterators
*iter // Returns the reference of the element to which the iterator points iter->name // Gets the iterator pointing to the name in the element The container holds the structure of the body equal to (*iter). Name. iter++ (-) //iter + + + + (-) ITER // as above only there is a difference between the first plus minus and the first operation iter1== (! =) Iter2 // judge that the elements referred to by both iterators are the same
The following table below is an additional operation supported by the string vector deque type iterator
Note: The list container only provides operations that are provided by all iterators above and cannot be compared using addition and subtraction (plus minus differs from self-increment)
C + + sequential containers (vector,list, Deque,stack,queue)