zoukankan      html  css  js  c++  java
  • 优先队列

     1 #include<iostream>
     2 #include<queue> 
     3 #include<vector> 
     4 using namespace std;
     5 
     6 struct cmp {
     7     bool operator ()(int &a, int &b) {
     8         return a > b;//从小到大
     9     }
    10 };
    11 
    12 int main(){
    13     int a[] = { 14,10,56,7,83,22,36,91,3,47 };
    14     priority_queue<int>que;
    15     priority_queue<int, vector<int>, cmp>que1;
    16 
    17     for (int i = 0; i < 10; i++) {
    18         que.push(a[i]);
    19         que1.push(a[i]);
    20     }
    21 
    22     while (!que.empty()) {
    23         cout << que.top() << " ";
    24         que.pop();
    25     }
    26 
    27     cout << endl;
    28     while (!que1.empty()) {
    29         cout << que1.top() << " ";
    30         que1.pop();
    31     }
    32 
    33     system("pause");
    34     return 0;
    35 }
  • 相关阅读:
    vector详解
    笔记
    积木大赛
    codevs 1086 栈(Catalan数)
    不要把球传我
    同余方程 (codevs1200)
    最小集合
    数的计算
    产生数
    逃跑的拉尔夫
  • 原文地址:https://www.cnblogs.com/gzu_zb/p/9530581.html
Copyright © 2011-2022 走看看