1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #include <queue> #include <vector>
using namespace std;
struct Node{ int a,b; Node(){} Node(int aa,int bb):a(aa),b(bb){}
bool operator < (const Node &r) const{ if(a==r.a) return b<r.b; else return a<r.a; } bool operator > (const Node &r) const{ if(a==r.a) return b>r.b; else return a>r.a; } };
int main(){
priority_queue<int> tmp_q; cout<<tmp_q.size()<<endl; cout<<tmp_q.empty()<<endl; tmp_q.push(1); cout<<tmp_q.size()<<endl; cout<<tmp_q.empty()<<endl; tmp_q.pop(); cout<<tmp_q.size()<<endl; cout<<tmp_q.empty()<<endl;
priority_queue<int> q; q.push(5); q.push(6); cout<<q.top()<<endl; q.pop(); cout<<q.top()<<endl; q.pop();
priority_queue<int, vector<int>, greater<int>> q_greater; q_greater.push(5); q_greater.push(6); cout<<q_greater.top()<<endl; q_greater.pop(); cout<<q_greater.top()<<endl; q_greater.pop();
priority_queue<double, vector<double>, less<double>> q_less; q_less.push(5.2); q_less.push(6.6); cout<<q_less.top()<<endl; q_less.pop(); cout<<q_less.top()<<endl; q_less.pop();
priority_queue<Node, vector<Node>, greater<Node>> q_greater_node; q_greater_node.push(Node(1,1)); q_greater_node.push(Node(1,2)); q_greater_node.push(Node(2,1)); q_greater_node.push(Node(2,2)); cout<<q_greater_node.top().a<<" "<<q_greater_node.top().b<<endl; q_greater_node.pop(); cout<<q_greater_node.top().a<<" "<<q_greater_node.top().b<<endl; q_greater_node.pop(); cout<<q_greater_node.top().a<<" "<<q_greater_node.top().b<<endl; q_greater_node.pop(); cout<<q_greater_node.top().a<<" "<<q_greater_node.top().b<<endl; q_greater_node.pop();
priority_queue<Node, vector<Node>, less<Node>> q_less_node; q_less_node.push(Node(1,1)); q_less_node.push(Node(1,2)); q_less_node.push(Node(2,1)); q_less_node.push(Node(2,2)); cout<<q_less_node.top().a<<" "<<q_less_node.top().b<<endl; q_less_node.pop(); cout<<q_less_node.top().a<<" "<<q_less_node.top().b<<endl; q_less_node.pop(); cout<<q_less_node.top().a<<" "<<q_less_node.top().b<<endl; q_less_node.pop(); cout<<q_less_node.top().a<<" "<<q_less_node.top().b<<endl; q_less_node.pop();
return 0; }
|