当前位置: 首页>>代码示例>>C++>>正文


C++ MaxHeap::Initialize方法代码示例

本文整理汇总了C++中MaxHeap::Initialize方法的典型用法代码示例。如果您正苦于以下问题:C++ MaxHeap::Initialize方法的具体用法?C++ MaxHeap::Initialize怎么用?C++ MaxHeap::Initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MaxHeap的用法示例。


在下文中一共展示了MaxHeap::Initialize方法的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;
}
开发者ID:jingyihiter,项目名称:Software-design-and-Practice,代码行数:28,代码来源:最大堆.cpp

示例2: _tmain

int _tmain(int argc, _TCHAR* argv[]){
	MaxHeap<int> myHeap;
	const int number = 10;
	int s;
	int key[10] = { 1, 4, 7, 8, 5, 2, 3, 6, 9, 0 };
	////若要使用键盘输入,把这些注释取消即可
	//cout << "请输入10个数:" << endl;
	//for (int i = 0; i < 10; i++)
	//{
	//	cin >> s;
	//	key[i] = s;
	//}
	cout << "原数组:" << endl;
	for (int i = 0; i < 10; i++)
		cout << key[i] << " ";
	cout << endl << endl;

	int myArray[11];////////
	for (int i = 0; i < 10; i++)
	{
		myArray[i + 1] = key[i];
	}
	myArray[0] = -1;
	myHeap.Initialize(myArray, number, 20);
	cout << "最大堆(层序):" << endl;
	cout << myHeap;
	HeapSort(myArray, number);
	cout << "堆排序:" << endl;
	for (int j = 1; j <= number; j++)
	{
		cout << myArray[j] << " ";
	}
	cout << endl << endl;

	cout << "Huffman编码:" << endl;
	int i;
	struct node huffmantree;
	memset(mark, 0, sizeof(mark));
	memset(huffman, 0, sizeof(huffman));
	for (i = 0; i < 10; i++)
	{
		huffman[i].key = key[i];
	}
	huffmantree = HuffmanTree(mark, huffman, 10);
	cout << "前序:";
	PreOrder(&huffmantree);
	cout << "\n中序:";
	MidOrder(&huffmantree);
	cout << endl << endl;

	cout << "二叉搜索树:" << endl;
	struct node *bs;
	for (int i = 0; i < 10; i++)
	{
		bstree[i].key = key[i];
	}
	bs = bstreeinsert(bstree);
	cout << "前序:";
	PreOrder(bs);
	cout << "\n中序:";
	MidOrder(bs);////////中序遍历(二叉搜索树的中序遍历是有序的)
	cout << endl;
	system("pause");
	return 0;
}
开发者ID:yushulinfeng,项目名称:DataStructure,代码行数:65,代码来源:ShiYan_Test.cpp


注:本文中的MaxHeap::Initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。