本文整理汇总了C++中MaxHeap::Size方法的典型用法代码示例。如果您正苦于以下问题:C++ MaxHeap::Size方法的具体用法?C++ MaxHeap::Size怎么用?C++ MaxHeap::Size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MaxHeap
的用法示例。
在下文中一共展示了MaxHeap::Size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: main
int main()
{
MaxHeap<int> mh;
mh.Push(3);
mh.Push(4);
mh.Push(8);
mh.Push(1);
mh.Push(9);
for (int i = 0; i < mh.Size(); ++i) {
std::cout << mh[i] << " ";
}
std::cout << std::endl;
std::cout << "==========" << std::endl;
std::cout << mh.Pop() << std::endl;
for (int i = 0; i < mh.Size(); ++i) {
std::cout << mh[i] << " ";
}
std::cout << std::endl;
std::cout << "==========" << std::endl;
MinHeap<int> minH;
minH.Push(3);
minH.Push(4);
minH.Push(8);
minH.Push(1);
minH.Push(9);
for (int i = 0; i < minH.Size(); ++i) {
std::cout << minH[i] << " ";
}
std::cout << std::endl;
std::cout << minH.Pop() << std::endl;
for (int i = 0; i < minH.Size(); ++i) {
std::cout << minH[i] << " ";
}
std::cout << std::endl;
std::cout << "---" << std::endl;
std::cout << re(3, 4) << std::endl;
std::vector<int> A{3, 6, 5};
A.pop_back();
for (auto &it : A) {
std::cout << it << std::endl;
}
std::cout << A.front() << "," << A.size() << std::endl;
return 0;
}