STL Priority Queue Priority_queue

Source: Internet
Author: User

1. Priority Queue Priority_queue

1) Maximum priority queue, minimum priority queue

2) Priority Queue Adapter STL Priority_queue

Priority_queue<int, Deque<int>> PQ;

Priority_queue<int, Vector<int>> PQ;

Pq.empty ()

Pq.size ()

Pq.top ()

Pq.pop ()

Pq.push (item)

#include <iostream>using namespacestd; #include"Queue" voidmain81 () {priority_queue<int> p1;//The default is the maximum priority queue//Priority_queue<int, Vector<int>, less<int> > p1;//It's equivalent to writingpriority_queue<int, vector<int, greater<int>> P2;//Minimum priority queueP1.push ( -); P1.push ( One); P1.push ( -); P1.push ( A); cout<<"Queue Size"<< p1.size () <<Endl; cout<<"Team Head"<< p1.top () <<Endl;  while(P1.size () >0) {cout<< p1.top () <<" ";    P1.pop (); } cout<<Endl; cout<<"Test minimum Priority queue"<<Endl; P2.push ( -); P2.push ( One); P2.push ( -); P2.push ( A);  while(P2.size () >0) {cout<< p2.top () <<" ";    P2.pop (); }}

STL Priority Queue Priority_queue

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.