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

📄 bstreefm.cpp

📁 C++描述的数据结构内容,在C++builder的环境中运行,这是第二部分
💻 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 + -