本文整理汇总了C++中MaxHeap::DeleteMax方法的典型用法代码示例。如果您正苦于以下问题:C++ MaxHeap::DeleteMax方法的具体用法?C++ MaxHeap::DeleteMax怎么用?C++ MaxHeap::DeleteMax使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MaxHeap
的用法示例。
在下文中一共展示了MaxHeap::DeleteMax方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int arg, char* argv[])
{
int dummy;
MaxHeap<int> mh;
mh.Insert(9).Insert(3).Insert(8).Insert(2).Insert(7).Insert(6).Insert(4).Insert(5).Insert(1);
cout << "MaxHeap elements by level: " << mh << endl;
mh.PrintTreeVertically(cout, 60);
mh.DeleteMax(dummy);
cout << "MaxHeap elements by level: " << mh << endl;
mh.PrintTreeVertically(cout, 60);
mh.DeleteMax(dummy);
cout << "MaxHeap elements by level: " << mh << endl;
mh.PrintTreeVertically(cout, 40);
mh.DeleteMax(dummy);
cout << "MaxHeap elements by level: " << mh << endl;
mh.PrintTreeVertically(cout, 40);
// Sorting
int a[] = { 0, 1, 4, 8, 9, 2, 1, 4, 3, 5, 7, 6, 3 };
#define ELEM_COUNT(a) (sizeof(a) / sizeof(a[0]))
MaxHeap<int>::Sort(a, ELEM_COUNT(a));
cout << "Sorting with MaxHeap:" << endl;
for (int i = 0; i < ELEM_COUNT(a); i++) {
cout << a[i] << ", ";
}
cout << endl;
return 0;
}
示例2: main
int main()
{
MaxHeap<int> heap;
int n=5;
cout<<"初始数组大小:"<<n<<endl;;
//cin>>n;
cout<<"输入的数组:";
//a = new int[n];
int a[6]={0,5,4,11,3,7};
for(int i=1;i<=n;i++)
//cin>>a[i];
cout<<a[i]<<" ";
cout<<endl;
cout<<"初始化为最大堆:"<<endl;
heap.Initialize(a,n,100);
heap.Output();
cout<<"\n插入10之后的最大堆:\n";
heap.Insert(10);
heap.Output();
cout<<"当前堆的大小:"<<heap.Size()<<endl;
cout<<"\n删除最大数之后的最大堆:\n";
int b=0;
heap.DeleteMax(b);
heap.Output();
cout<<"当前堆的大小:"<<heap.Size()<<endl;
getchar();
return 0;
}