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

📄 main.cpp

📁 二叉树的实现
💻 CPP
字号:
//程序名:main.cpp
//      程序功能:二叉树基本操作的实现
//          作者:黄秋旋
//          日期:2008.11.9
//          版本:1.0
//      修改内容:
//      修改日期:
//      修改作者:
//对应类实现文件: tree.h
//对应主程序文件: tree.cpp

#include<iostream.h>
#include"tree.h"

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//主函数
//返回值:无

void main()
{
	TREE Tree1;                       //Tree1 object
	int first=1,choice;
    BTreeNode *bt=NULL;
	int finish=0;
	while(!finish)
	{   
		cout<<"********************MENU*******************************";
		cout<<"\n 1:Create a tree";
		cout<<"\n 2:Trave the tree with recursive algorithm of preamble";
        cout<<"\n 3:Trave the tree with nonrecursive algorithm of preamble";
		cout<<"\n 4:Trave the tree whith recursive algorithm of mid-rank method";
        cout<<"\n 5:Trave the tree whith noncursive algorithm of mid-rank method";
        cout<<"\n 6:Trave the tree whith recursive algorithm of surf-order";
        cout<<"\n 7:Trave the tree whith nonrecursive algorithm of surf-order"; 
        cout<<"\n 8:Trave the tree whith layerorder";
	    cout<<"\n 9:The altitude of the tree";
        cout<<"\n 10:The total number of the leaves";
        cout<<"\n 11:Print the tree: ";
		cout<<"\n 12:Exit";
        cout<<"\n Please inout the choice 1 to 12:  ";
		cin>>choice;
		switch(choice)
		{
		case 1:
			Tree1.Create(first);                               //创建二叉树
			cout<<"\n Please input the letters: ";
			first=1;
			cout<<endl;
			break;
		case 2:
			cout<<"The result of preorder: ";                 //调用前序递归遍历
			Tree1.Preorder(bt, first);
           	first=1;
			cout<<endl;
			break;
        case 3: 
        	cout<<"The result of preorder: ";                 //调用前序非递归遍历
            Tree1.Preorderf(bt);
			first=1;
			cout<<endl;
			break;
	   case 4:
	        cout<<"The result of inorder: ";                  //调用中序递归遍历
            Tree1.Inorder(bt, first);
            first=1;
			cout<<endl;
			break;
	   case 5:
            cout<<"The result of inorder: ";                  //调用中序非递归遍历
			Tree1.Inoderf(bt);
			first=1;
			cout<<endl;
			break;
	   case 6:
            cout<<"The result of postorder: ";                //调用后序递归遍历
			Tree1.Postorder(bt, first);
		    first=1;
			cout<<endl;
			break;
       case 7:
            cout<<"The result of postorder: ";                  //调用后序非递归遍历
			Tree1.Postorderf(bt);
            first=1;
			cout<<endl;
			break;
		case 8:
            cout<<"The result of layerorder: ";                  //调用层次遍历
			Tree1.Layerorder(bt);
			first=1;
			cout<<endl;
			break;
        case 9:
			cout<<"The altitude of the tree is: ";               //调用求树高函数
			cout<<Tree1.Altitude(bt, first);
		    cout<<endl;
			break;
		case 10:
			cout<<"The number of the leaves is: ";                //调用求子叶数函数
			cout<<Tree1.Number();
		    cout<<endl;
			break;
        case 11:
			Tree1.Print(bt,first);                                //调用输出二叉树函数
			cout<<endl;
			break;
		case 12:
			finish=1;                                             //结束程序
			break;
		}
	}
}

⌨️ 快捷键说明

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