zoukankan      html  css  js  c++  java
  • STL:优先队列Priority Aueue

    The functions associated with priority queue are:
    empty() – Returns whether the queue is empty
    size() – Returns the size of the queue
    top() – Returns a reference to the top most element of the queue
    push(g) – Adds the element ‘g’ at the end of the queue
    pop() – Deletes the first element of the queue

    #include <iostream>
    #include <queue>
     
    using namespace std;
     
    void showpq(priority_queue <int> gq)
    {
        priority_queue <int> g = gq;
        while (!g.empty())
        {
            cout << ' ' << g.top();
            g.pop();
        }
        cout << ' ';
    }
     
    int main ()
    {
        priority_queue <int> gquiz;
        gquiz.push(10);
        gquiz.push(30);
        gquiz.push(20);
        gquiz.push(5);
        gquiz.push(1);
     
        cout << "The priority queue gquiz is : ";
        showpq(gquiz);
     
        cout << " gquiz.size() : " << gquiz.size();
        cout << " gquiz.top() : " << gquiz.top();
     
     
        cout << " gquiz.pop() : ";
        gquiz.pop();
        showpq(gquiz);
     
        return 0;
    }

     
    The output of the above programs is :

    The priority queue gquiz is :     30    20    10    5    1
    
    gquiz.size() : 5
    gquiz.top() : 30
    gquiz.pop() :     20    10    5    1
  • 相关阅读:
    Quartz 基本概念及原理
    quartz-2.2.x 快速入门 (1)
    hive踩过的小坑
    spring profile 多环境配置管理
    win10窗口设置眼睛保护色
    优雅地在markdown插入图片
    Using Spring Boot without the parent POM
    isDebugEnabled作用
    Log 日志级别
    为什么要使用SLF4J而不是Log4J
  • 原文地址:https://www.cnblogs.com/passion-sky/p/8579363.html
Copyright © 2011-2022 走看看