#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

class priority_queue
{
private:
    vector<int> data;

public:
    void push(int t){
        data.push_back(t);
        push_heap(data.begin(), data.end());
    }

    void pop(){
        pop_heap(data.begin(), data.end());
        data.pop_back();
    }

    int top() { return data.front(); }
    int size() { return data.size(); }
    bool empty() { return data.empty(); }
};


int main()
{
    priority_queue test;
    test.push(3);
    test.push(5);
    test.push(2);
    test.push(4);

    while (!test.empty()){
        cout << test.top() << endl;
        test.pop();
    }

    return 0;

}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2021-08-22
  • 2021-12-27
  • 2021-09-19
  • 2021-04-03
  • 2021-12-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
相关资源
相似解决方案