An adapter is a template class that provides interface ing. The adapter implements new functions based on other classes. member functions can be added, hidden, or merged to obtain new functions.STL provides three container adapters: queue, priority_queue, and stack.These adapters are the wrapper that wraps a certain sequence container in vector, list, And deque. Note: The adapter does not provide an iterator and cannot insert or delete multiple elements at the same time. URL: http://www.cnblogs.com/archimedes/p/cpp-adapter.html. The data structure of the queue (first-in-first-out (FIFO) is available only for the deque and list containers. Use the default deque for most purposes. 1. Use the header file # include <queue> 2. Common functions
The data structure of the stack (advanced post-output (FILO) can use any of the three standard ordered containers vector, deque, and list as the underlying model of the stack. 1. header files # include <stack> 2. Common functions
<Priority_queue> internal implementation: heap priority_queue <T, Sequence, Compare> supports Operation: push () O (logn) pop () O (logn) top () O (1) the first element in the access queue. Unlike the queue, See also: push_heap (), pop_heap ()... Example of in <algorithm> priority_queue usage
#include <queue><vector> <> maxheap; ()( a, a ><,vector<>,cmp> minheap;
Priority_queue compares the priority of function comparison functions. You can use the default value or reload your own comparison functions. 1) assume that the element in the priority queue is a struct and you need to sort a variable. In this case, you can reload the operator in the struct:
priority_queue<, vector<>, cmp> seq; < ( Test &a) seq < a.seq;
2) If the variable is sorted by a variable related to an element in the priority queue and this variable is not in the struct, you can refer to the greater <int> () method to overload (), the procedure is as follows:
priority_queue<, vector<>, cmp> ()( a, b) { d[a] >