二叉堆属性

题目描述

C++代码
#include <iostream>
#include <queue>
using namespace std;
int main() {
priority_queue<int> big_heap;
priority_queue<int, vector<int>, greater<int>> small_heap;
priority_queue<int, vector<int>, less<int>> big_heap2;
if (big_heap.empty()) {
printf("big_heap is empty!\n");
}
int test[] = {6, 10, 1, 7, 99, 4, 33};
for (int i = 0; i < 7; i++) {
big_heap.push(test[i]);
}
printf("big_heap.top = %d\n", big_heap.top());
big_heap.push(1000);
printf("big_heap.top = %d\n", big_heap.top());
for (int i = 0; i < 3; i++) {
big_heap.pop();
}
printf("big_heap.top = %d\n", big_heap.top());
printf("big_heap.size = %d\n", big_heap.size());
return 0;
}
输出
big_heap is empty!
big_heap.top = 99
big_heap.top = 1000
big_heap.top = 10
big_heap.size = 5