⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chapter5-14.cpp

📁 STL程序员开发指南源码
💻 CPP
字号:
//文件名:CHAPTER5-14.cpp
#include <iostream>
#include <queue>
#include <deque>
#include <vector>
#include <functional>
using namespace std ;
// Using priority_queue with deque
// Use of function greater sorts the items in ascending order
typedef deque<int> INTDQU;
typedef priority_queue<int> INTPRQUE;
// Using priority_queue with vector
// Use of function less sorts the items in descending order
typedef vector<char> CHVECTOR;
typedef priority_queue<char> CHPRQUE;
void main(void)
{
    int size_q;
    INTPRQUE   q;
    CHPRQUE    p;
    // Insert items in the priority_queue(uses deque)
    q.push(42);
    q.push(100);
    q.push(49);
    q.push(201);
    // Output the size of priority_queue
    size_q = q.size();
    cout << "size of q is:" << size_q << endl;
   // Output items in priority_queue using top()
    // and use pop() to get to next item until
    // priority_queue is empty
    while (!q.empty()) { cout << q.top() << endl; q.pop(); }  // Insert items in the priority_queue(uses vector)
    p.push('c');
    p.push('a');
    p.push('d');
    p.push('m');
    p.push('h');    // Output the item at the top using top()
    cout << p.top() << endl;    // Output the size of priority_queue
    size_q = p.size();
    cout << "size of p is:" << size_q << endl;    // Output items in priority_queue using top()
    // and use pop() to get to next item until priority_queue is empty
    while (!p.empty()) { cout << p.top() << endl; p.pop(); }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -