呃呃呃 天梯前几个小时哈哈哈
学一下
代码
#include<bits/stdc++.h>
using namespace std;
struct node
{
int num;
int id;
node(){}
node(int a, int b){num = a; id = b;}
};
int main()
{
//make_heap 怎么用
vector<int>vec{6,4,7,1,5};
make_heap(vec.begin(),vec.end()); //有less<int>() greater<int>()
for(int i = 0 ; i < 5; i ++)
printf("%d ",vec[i]);
printf("\n");
//这个是按照堆的pushDown n / 2 建立一个堆
//push_heap
vec.push_back(99);
push_heap(vec.begin(),vec.end());
for(int i = 0 ; i < 6; i ++)
printf("%d ",vec[i]);
printf("\n");
//pop_heap
pop_heap(vec.begin(),vec.end());
for(int i = 0 ; i < 6; i ++)
printf("%d ",vec[i]);
printf("\n");
return 0;
}
结果
7 5 6 1 4
99 5 7 1 4 6
7 5 6 1 4 99