minheapm.cpp
来自「数据结构算法(C++实现)最小堆的类定义和实现。」· C++ 代码 · 共 42 行
CPP
42 行
//最小堆类的测试minheapm.cpp
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
typedef int ElemType;
#include "minheap.cpp"
void PrintArray(int a[],int n)
{for(int i=0;i<n;i++)
cout<<setw(3)<<a[i];
cout<<endl;
}
void main()
{cout<<"minheapm.cpp运行结果:\n";
ElemType b[10];
for(int i=0;i<10;i++)
b[i]=random(50);
cout<<"输出数组b:\n";
PrintArray(b,10);
minheap H(10),H1(10);
for(int i=0;i<10;i++)
H.heapInsert(b[i]);
cout<<"输出当前堆H的堆顶元素:\n";
cout<<setw(3)<<H.GetTop()<<endl;
cout<<"输出插入后数组b:\n";
PrintArray(b,10);
cout<<"输出逐个删除的H堆中元素:\n";
while(!H.heapEmpty())
cout<<setw(3)<<H.heapDelete();
cout<<endl;
for(int i=0;i<10;i++)
H1.heapInsert(random(80));
cout<<"输出当前堆H1的堆顶元素:\n";
cout<<setw(3)<<H1.GetTop()<<endl;
cout<<"输出逐个删除的H1堆中元素:\n";
while(!H1.heapEmpty())
cout<<setw(3)<<H1.heapDelete();
cout<<endl;
H.Destroyheap();H1.Destroyheap();
getch();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?