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

📄 exam.cpp

📁 森林的层次遍历、广义表输出等关于森林的一些基本操作
💻 CPP
字号:
#include"exam5.h"
void main()
{
	Tree<char> t;int choice=0;
	while(true)
	{
		system("cls");
		cout<<"				树和森林实验\n";
		cout<<"	1.将一棵树(或森林)转换为二叉树	2.求森林的高度\n";
		cout<<"	3.按层次方式遍历森林			4.输出一个森林的广义表形式\n";
		cout<<"	5.输出一个森林中每个结点的值及其对应的层次数	0.退出\n";
		cout<<"请输入选择项目:";cin>>choice;
		if(choice==0)break;
		if(choice==1)
		{
			system("cls");
			BT<char> b;t.filecreat(t.root);
			t.trans(t.root,b.root);cout<<"转换为二叉树后中序遍历:"<<endl;
			b.inOrder(b.root);cout<<endl;
			system("pause");continue;
		}
		if(choice==2)
		{
			system("cls");
			t.filecreat(t.root);
			cout<<"此树高度为:";
			cout<<t.height(t.root)<<endl;
			system("pause");continue;
		}
		if(choice==3)
		{
			system("cls");
			t.filecreat(t.root);
			cout<<"层次遍历为:"<<endl;
			t.display1(t.root);cout<<endl;
			system("pause");continue;
		}
		if(choice==4)
		{
			system("cls");
			t.filecreat(t.root);
			cout<<"广义表形式为:"<<endl;
			t.show(t.root);
			system("pause");continue;
		}
		if(choice==5)
		{
			system("cls");
			t.filecreat(t.root);
			t.display2(t.root,1);cout<<endl;
			system("pause");continue;
		}
		else
		{
			cout<<"选择无效!"<<endl;system("pause");continue;
		}
	}
}

⌨️ 快捷键说明

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