After the stack is a first-out (FILO) table, insert and delete restrictions only in the top of the stack.
- push () at the top of the stack add elements
- pop () to remove the top element
- empty () stack is empty
- () Number of elements in the stack size
- top () the top element
a vector is capable of storing any type of dynamic array.
- Example: vector <int> vec;
- Two-dimensional array: vector <vector <int >> vec;
- Tail pressed: vec.push_back (1);
- Indexed access: vec [0];
- Iterator visit:
vector<int>::iterator it; for(it = vec.begin(); it!= vec.end(); it++) cout << *it << endl;
- Insert elements: vec.insert (vec.begin () + i, a);
- Remove elements: vec.erase (vec.begin () + i);
- Vector Size: vec.size ();
- Empty vector: cev.clear ();
- If the vector length is longer, easily lead to memory leaks, and inefficient;
- As a function of parameters or return values, using the reference &: void func (vector <int> & a)
- Flip the elements, sort
#include<algorithm> reverse(vec.begin(), vec.end()); sort(vec.begin(), vec.end()); //默认升序排列
The basic operation of the queue are:
enqueued as Example: q.push (x); x to the end of the queue.
Dequeue, as described in Example: q.pop (); pop the first element of the queue, attention, and will not return value is the pop-up element.
The first team to access elements such cases: q.front (), that is the first to be pushed into the queue elements.
Access to the tail element, as described in Example: q.back (), i.e., the final element is pressed into the queue.
Analyzing empty queue, as described in Example: q.empty (), when the queue is empty, returns true.
The number of elements in the access queue, as described in Example: q.size ()
key set storage container only, a simple set of keys, where the key is not repeated.