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
0
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;
}