Learning algorithm starts from 0 - Basic data structure (stack and the priority queue 2.7)

Heap heap sort mentioned in

Priority queue is essentially a stack may logn added complexity of a time element in logn remove the top of the stack of elements within the time, and in O (1) access to the highest priority queue within a time element

c ++ Standard Library

head File

#include<queue>

definition

priority_queue<int>q;

Last priority queue is empty

q.empty();

Returns the element of highest priority squad

q.top();

X is added to the queue

q.push(x);

Delete the highest priority elements

q.pop();

Returns the number of elements in the current squad

q.size();

Example: the priority queue can also do a search problem (when doing a search problem with queues, in essence, is the time to increase the priority of a priority queue)

Guess you like

Origin www.cnblogs.com/wz-archer/p/11713515.html