?? main.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 + -