一、优先队列c++实现源代码
#include <iostream>
#include <assert.h>
using namespace std;
//function: 返回最大值
int HeapMaximum(int* array);
//function: 返回最大值并删除
int HeapRactMax(int*& array, int n);
void Exchange(int* a, int* b);
//function: 维护堆的性质
void RecursionHeap(int* array, int i, int n);
//function: 建堆
void BuildHeap(int* array, int n);
//function: 关键字的值增加到key
void IncreaseKey(int* array, int i, int key);
//function: 插入一个元素
void InsertKey(int*& array, int key, int n);
int main()
{
int* array = new int[10];
for (int i = 0; i < 10; ++ i)
cin >> array[i];
BuildHeap(array, 10);
for (i = 0; i < 10; ++ i)
cout << array[i] << " ";
cout << endl;
cout << HeapMaximum(array) << endl; //测试最大值
cout << HeapRactMax(array, 10) << endl; //
for (i = 0; i < 9; ++ i)
cout << array[