?? bstreefm.cpp
字號:
//二叉搜索樹類的相關操作的測試BSTreeFM.cpp
#include<iostream.h>
#include<iomanip.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
#include "BSTreeF.h"
#include "BSTreeF.cpp"
void main()
{cout<<"BSTreeFM.cpp運行結果:\n";
ElemType b[10]={{"1001",72},{"1002",84},{"1009",83},{"1010",75},
{"1012",87},{"1013",79},{"1019",91},{"1020",84}};
ElemType m={"1014",89},m2={"1016",90};
int n,i,m1=8;
char f[20]="D:.\\file.txt";
BSTree<ElemType> t,*B;
t.InitBSTree(B);
t.CreateBSTree(B,b,m1);
n=t.BSTreeCount(B);
cout<<"二叉搜索樹的所有結點數="<<n<<endl;
if(!t.BSTreeEmpty(B))
cout<<"二叉搜索樹非空!\n";
else
cout<<"二叉搜索樹為空!\n";
cout<<"中序遍歷:";t.Inorder(B);cout<<endl;
n=t.BSTreeDepth(B);
cout<<"二叉搜索樹的深度="<<n<<endl;
n=t.BSTreeLeafCount(B);
cout<<"二叉搜索樹的所有葉子結點數="<<n<<endl;
cout<<"按二叉搜索樹的廣義表:\n";
t.PrintBSTree(B);cout<<endl;
t.Insert(B,m);
cout<<"中序遍歷:";t.Inorder(B);cout<<endl;
if(t.Find(B,m)) cout<<"查找成功!\n";
else cout<<"查找不成功!\n";
m=b[6];
if(t.Update(B,m,m2)) cout<<"更新成功!\n";
else cout<<"更新不成功!\n";
cout<<"中序遍歷:";t.Inorder(B);cout<<endl;
n=t.BSTreeCount(B);
cout<<"二叉搜索樹的所有結點數="<<n<<endl;
n=t.BSTreeDepth(B);
cout<<"二叉搜索樹的深度="<<n<<endl;
if(t.Delete(B,m)) cout<<"刪除成功!\n";
else cout<<"刪除不成功!\n";
cout<<"中序遍歷:";t.Inorder(B);cout<<endl;
n=t.BSTreeDepth(B);
cout<<"二叉搜索樹的深度="<<n<<endl;
n=t.BSTreeCount(B);
cout<<"二叉搜索樹的所有結點數="<<n<<endl;
cout<<"輸出所有成績:\n";
t.WriteFile(f,B);t.ReadFile(f,B);
cin.get();}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -