资源简介
数据结构课程设计-二叉排序树(附详细文档说明).rar

代码片段和文件信息
#include
#include
#include
#include
#include
using namespace std;
struct node{
int num;
node *chl*chr;
};
bool flagdel;
ifstream in(“sort.txt“);
void Insert(const int &tempnode **root)
{
if( *root==NULL )
{
*root = new node;
(*root)->chl = (*root)->chr = NULL;
(*root)->num = temp;
}
else if( (*root)->num Insert(temp&(*root)->chr);
else
Insert(temp&(*root)->chl);
}
void Delete(const int &keynode **p)
{
if( *p==NULL )
{
cout<<“删除错误,不存在该元素!“< flagdel = false;
return;
}
node *temp=NULL;
if( (*p)->num==key )
{
if( (*p)->chl==NULL )
{
temp = *p;
*p = (*p)->chr;
delete temp;
}
else if( (*p)->chr==NULL )
{
temp = *p;
*p = (*p)->chl;
delete temp;
}
else
{
temp = (*p)->chl;
node *front=NULL;
while( temp->chr )
{
front = temp;
temp = temp->chr;
}
front->num = temp->num;
if( front!=temp )
front->chr = temp->chl;
else
front->chl = temp->chl;
delete temp;
}
}
else if( (*p)->num>key )
Delete(key&(*p)->chl);
else
Delete(key&(*p)->chr);
}
bool Find(const int &keynode *pnode *netint &depth)
{
if( p==NULL )
return false;
depth++;
net = p;
if( p->num==key )
return true;
else if( p->num>key )
return Find(keyp->chlnetdepth);
else
return Find(keyp->chrnetdepth);
}
void Print(const node *p)
{
if( p==NULL )
return;
cout<num<<‘ ‘;
Print(p->chl);
Print(p->chr);
}
bool Menu(node **root)
{
int choicenumdepth;
node *net;
bool suc;
cout< cout< cout<<“\t 1.插入 \t2.查找“< cout<<“\t 3.遍历 \t4.删除“< cout<<“\t 5.退出菜单“< cout<<“输入选项:“;
cin>>choice;
if( choice==5 )
return false;
cout< switch( choice )
{
case 1:
cout<<“输入要插入的数字:“< cin>>num;
Insert(num&(*root));
cout<<“插入成功!“< break;
case 2:
cout<<“输入查找元素:“< cin>>num;
if( *root==NULL )
cout<<“二叉树为空,查找失败!“< else
{
depth = 0;
net = NULL;
suc = Find(num*rootnetdepth);
if( suc )
cout<<“查找成功。“< else
cout<<“查找失败,没有该元素。“<
cout<<“查找深度 : “< }
break;
case 3:
cout<<“中序遍历二叉排序树“< if( *root==NULL )
cout<<“二叉树为空!“< else
Print(*root);
break;
case 4:
cout<<“输入要删除的数字:“< cin>>num;
flagdel = true;
Delete(num&(*root));
if( flagdel )
cout<<“删除成功!“< break;
case 5:
return false;
default:
cout<<“错误选择。“<
}
cout< return true;
}
int main()
{
int i;
int numdepth;
bool first=true;
cout<<“\t\t\t\t*****初始化*****“<<
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 169984 2012-02-10 21:05 二叉排序树 .doc
文件 3577 2011-09-28 13:44 二叉排序树.cpp
文件 918755 2011-09-28 13:44 二叉排序树.exe
----------- --------- ---------- ----- ----
1092316 3
- 上一篇:用汇编语言实现的记事本
- 下一篇:Write an ALSA Driver
相关资源
- PID_AutoTune_v0.rar
- vspd7.2.308.zip
- 价值2k的H漫画小说系统
- Pythonamp;课堂amp;笔记(高淇amp;400;集第
- ddos压力测试工具99657
- UML建模大全
- 开源1A锂电池充电板TP4056原理图+PCB
- m1卡 ic卡可选择扇区初始化加密软件
- TSCC.exe
- FTP课程设计(服务端+客户端)
- 计算机图形学 边填充算法实现代码
- 电力系统潮流计算程序集合
- oracle数据迁移项目实施方案
- Web Api 通过文件流 文件到本地
- Visio图标-最新最全的网络通信图标库
- Spire API文档
- OpenGL参考手册
- Python中Numpy库最新教程
- SPD博士V5.3.exe
- 直流无刷电机方波驱动 stm32 例程代码
- layui后台管理模板
- 仿知乎界面小程序源代码
- 云平台-阿里云详细介绍
- photoshop经典1000例
- scratch垃圾分类源码(最终版本).sb
- IAR ARM 7.8破解
- TI CCS V5.4 安装步骤及破解文件
- 松下plc FP-XH的驱动
- 局域网硬件信息收集工具
- 加快Windows XP操作系统开机速度
评论
共有 条评论