STL -- container adapter (queue, priority_queue, stack)

Source: Internet
Author: User

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] >

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.