Homework Introduction

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	priority_queue<int> pq;
	pq.push(5);  // 5
	pq.push(8);  // 8 5
	pq.push(6);  // 8 6 5
	cout << pq.size() << endl; // 8
	while(!pq.empty()){ // 
		cout << pq.top() <<" ";
		pq.pop();
	}
	return 0;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;

int main() {
	priority_queue<int,vector<int>,greater<int> > pq;
	pq.push(5);  // 5
	pq.push(8);  // 5 8 
	pq.push(6);  // 5 6 8 
	cout << pq.size() << endl; // 5
	while(!pq.empty()){ // 
		cout << pq.top() <<" ";
		pq.pop();
	}
	return 0;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
struct node {
	int x;
	int id;
	bool operator<(const node& rhs) const {
		return x > rhs.x;
	}
};

int main() {
	priority_queue<node> pq;
	pq.push({5,3});  // 5
	pq.push({8,2});  // 5 8
	pq.push({6,4});  // 5 6 8
	cout << pq.size() << endl; // 3
	while(!pq.empty()) { //
		cout << pq.top().x <<" ";
		pq.pop();
	}
	return 0;
}
小根堆:priority_queue<int,vector<int>,greater<int> > pq;

大根堆:
priority_queue<int,vector<int>,less<int> > pq;
priority_queue<int> pq;
Status
Done
Problem
11
Open Since
2024-7-13 0:00
Deadline
2024-8-31 23:59
Extension
24 hour(s)