maxheap.cpp

来自「一本全面剖析C++数据结构算法的书籍」· C++ 代码 · 共 29 行

CPP
29
字号
// test max heap class#include <iostream.h>#include "maxheap.h"void main(void){   MaxHeap<int> H(4);   int x;   H.Insert(10).Insert(20).Insert(5);   cout << "Elements in array order" << endl;   H.Output();   try {H.Insert(15);        cout << "Insert of 15  succeeded" << endl;        H.Insert(30);        cout << "Insert of 30  succeeded" << endl;}   catch (NoMem)      {cout << "An insert has failed"  << endl;}   cout << "Elements in array order" << endl;   H.Output();   cout << "The max element is " << H.Max() << endl;   H.DeleteMax(x);   cout << "Deleted max element " << x << endl;   H.DeleteMax(x);   cout << "Deleted max element " << x << endl;   cout << "Elements in array order" << endl;   H.Output();}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?