⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ds6_14.cpp

📁 这是清华大学出版社的《数据结构》的电子文档讲义
💻 CPP
字号:
// ds6_14.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "tree.h"

void heapprint(minHeap<int>& mh,int s){
	int i,j,k=0,m=1,n;
	cout<<endl;
	for(i=1; i<5; i++){
		for (j=0; j<10-i; j++) cout<<"   ";
		for (j=0; j<m; j++) 
			if(k<s){
				for(n=3; n<10-m; n++)cout<<"  ";
				cout<<mh.heap[k++]<<",";
				}
		cout<<endl;
		m*=2;
		}
	cout<<endl;
	}

int main(int argc, char* argv[])
{
	int j,k=0,m=1,n,s=8;
	int c[8]={4,2,5,8,3,6,10,14};
	minHeap<int> mh1(15);
	for(int i=0; i<s; i++){	
//		cin>>j;					//键盘输入:                   4,2,5,8,3,6,10,14
		j=c[i];
		mh1.insert(j);			//加入最小堆mh1
		heapprint(mh1,i+1);
		}
//	heapprint(mh1,i);

	mh1.removeMin(n);k=0;m=1;s--;
	heapprint(mh1,s);

	mh1.removeMin(n);k=0;m=1;s--;
	heapprint(mh1,s);

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -