笔记-堆
2025-04-13 11:23:06
发布于:北京
#include <bits/stdc++.h>
using namespace std;
int main(){
    priority_queue<int> q;
    q.push(3);	//在大根堆里加入一个元素
	q.size();	//返回堆里面元素的个数
	while(q.size()){
		cout << q.top();	//输出最大元素
		q.pop();	//删除大根堆中的最大元素 
	}
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
    priority_queue<int,vector<int>,greater<int>> q;
    q.push(3);	//在小根堆里加入一个元素
	q.size();	//返回堆里面元素的个数
	while(q.size()){
		cout << q.top();	//输出最小元素
		q.pop();	//删除小根堆中的最小元素 
	}
    return 0;
}
这里空空如也











有帮助,赞一个