#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<xfunctional>
using namespace std;
class Priority_queue{
private:
int h_size;
vector<int> elem;
public:
Priority_queue(){
elem.push_back(-1);//we do not use the elem[0]
h_size = 0;
}
int& operator[](int i){
return elem[i];
}
void Tune(int i){
int index = i;
int temp = elem[i];
int max_temp = elem[i];
while (2 * i <= h_size){
if (elem[2 * i] < max_temp){
max_temp = elem[2*i];
index = 2 * i;
}
if (2 * i + 1 <= h_size){
if (elem[2 * i + 1] < max_temp){
max_temp = elem[2 * i+1];
index = 2 * i + 1;
}
}
if (index == i) break;
else{
elem[i] =elem[index] ;
i=index;
}
}
elem[index]
算法导论(min-priority-queue 最小优先队列的部分实现)
最新推荐文章于 2022-08-10 11:04:11 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)