⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 minheap.cpp

📁 datastucutre and algorithms, application, in C
💻 CPP
字号:
// test min heap

#include <iostream>
#include "minHeap.h"

using namespace std;

int main(void)
{
   // test constructor and push
   minHeap<int> h(4);
   h.push(10);
   h.push(20);
   h.push(5);

   cout << "Heap size is " << h.size() << endl;
   cout << "Elements in array order are" << endl;
   cout << h << endl;

   h.push(15);
   h.push(30);

   cout << "Heap size is " << h.size() << endl;
   cout << "Elements in array order are" << endl;
   cout << h << endl;

   // test top and pop
   cout << "The min element is " << h.top() << endl;
   h.pop();
   cout << "The min element is " << h.top() << endl;
   h.pop();
   cout << "The min element is " << h.top() << endl;
   h.pop();
   cout << "Heap size is " << h.size() << endl;
   cout << "Elements in array order are" << endl;
   cout << h << endl;

   // test initialize
   int z[10];
   for (int i = 1; i < 10; i++)
      z[i] = 10 - i;
   h.initialize(z, 9);
   cout << "Elements in array order are" << endl;
   cout << h << endl;
   return 0;
}

⌨️ 快捷键说明

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