- 8
- 0
- 约6.08千字
- 约 18页
- 2017-10-06 发布于河南
- 举报
实验5 树的宽度 层次遍历(Experiment 5 tree width hierarchy traversal)
实验5 树的宽度 层次遍历(Experiment 5 tree width hierarchy traversal)
#包含iostream
使用名称空间;
#定义N 20
/ /自定义类型
枚举状态码{成功,失败,under_flow,over_flow,range_error,duplicate_error,
not_present,entry_inserted,entry_found,访问,并且};
/ /二叉树结点类
模板类的作用域中的
结构bintreenode
{
/ /数据成员:
数据域;/ /数据域
bintreenode 域 * leftchild;/ /左孩子指针域
bintreenode 域 *右孩子;/ /右孩子指针域
/ /构造函数:
bintreenode();/ /无参数的构造函数
BinTreeNode(常量域和Val,/ /已知数据元素值,指向左右孩子的指针构造一个结点
bintreenode 域 *左右= null,
bintreenode 域 * rchild = null);
};
/ /二叉树结点类的实现部分
模板类的作用域中的
BinTreeNode 域::bintreenode()
/ /操作结果:构造一个叶结点
{
leftchild =右孩子= null;/ /叶结点左右孩子为空
}
模板类的作用域中的
BinTreeNode 域::BinTreeNode(常量域和Val,
bintreenode 域 *左右,bintreenode 域 * rchild)
/ /操作结果:构造一个数据域为Val,左孩子为左右右孩子为rchild的结点
{
数据= val;/ /数据元素值
leftchild =左右;/ /左孩子
右孩子= rchild;/ /右孩子
}
/ /二叉树类
模板类的作用域中的
类序
{
受保护的:
/ /二叉树的数据成员:
bintreenode 域 *根;
/ /辅助函数:
bintreenode 域 * copytreehelp(bintreenode 域 *复印件);/ /复制二叉树
无效destroyhelp(bintreenode 域 * R);/ /销毁以R为根二叉树
int WidthHelp(const bintreenode 域 R)const;
bintreenode 域 * parenthelp(bintreenode 域 * R,
域 * const bintreenode CUR)const;//返回Cur的双亲
公共:
/ /二叉树方法声明及重载编译系统默认方法声明:
binarytree();/ /无参数的构造函数
虚拟~ binarytree();/ /析构函数
bintreenode 域 * getroot() const;//返回二叉树的根
布尔empty() const;//判断二叉树是否为空
width() const int;
BinaryTree(const ElemType E);/ /建立以E为根的二叉树
BinaryTree(const BinaryTree 域及复印件);/ /复制构造函数
BinaryTree(bintreenode 域 R);/ /建立以R为根的二叉树
BinaryTree 域 运算符=(const BinaryTree 域及复印件);/ /赋值运算符重载
};
模板类的作用域中的
无效的CreateBinaryTreeHelp(bintreenode 域 * R,输出预[ ],在[输出],
preright int,int int预留,左,右)int;
/ /已知二叉树的先序序列预[预留.. preright ]在[右]和中序序列左..构造以R为根的
/ /二叉树
模板类的作用域中的
域序及createbinarytree(ElemType预[ ],在[ ],int n输出);
/ /已知先序和中序序列构造二叉树
/ /二叉树类的实现部分
模板类的作用域中的
BinaryTree 域::binarytree()
/ /操作结果:构造一个空二叉树
{
根=空;
}
模板类的作用域中的
BinaryTree 域::~ binarytree()
/ /操作结果:销毁二叉树--析造函数
{
destroyhelp(根);
}
模板类的作用域中的
bintreenode 域 * 域序::getroot() const
/ /操作结果:返回二叉树的根
{
返回根;
}
模板类的作用域中的
Bool binarytree ElemType :: empty () const.
/ / 操作结果: 判断二叉树是否为空
{
Return root = = null;
}
The templat
您可能关注的文档
- 天津(Tianjin).doc
- 天津违章摄录地点大全(Tianjin illegal video recording site).doc
- 天然药材---葛根(Pueraria lobata).doc
- 天然药物化学总论(Journal of natural medicinal chemistry).doc
- 天翼宽带光盘安装使用说明(Tianyi broadband CD-ROM installation instructions).doc
- 天能科技竞争优势(Day to day technology competitive edge).doc
- 天门市住房公积金管理实施细则(Detailed rules for the implementation of the Tianmen housing provident fund management).doc
- 太仓市2009~2010学年第一学期期终考试试卷 初三化学(Taicang City, 2009 ~ 2010 year first semester final exam of Junior Chemistry).doc
- 太原市城市房屋拆迁管理办法(Measures for the administration of urban housing units in Taiyuan).doc
- 太和(Wo).doc
最近下载
- 2026年浙江档案职称考试(档案工作实务)历年参考题库含答案详解.docx VIP
- 南通佳宜有限公司办公楼建筑结构设计.docx
- 拼拼豆教程及图案汇总[已排版可直接打印].doc VIP
- 共情传播视角下的网络微短剧叙事分析.docx VIP
- 贵阳市2024届高三适应性考试(一)一模物理试卷(含答案).docx
- 高中物理运动和力的关系10道计算题专题.docx VIP
- 语言学及应用语言学专业硕士研究生培养方案﹙050102﹚.docx VIP
- 10以内加减混合填空题(30页).docx
- 三相四线电能表不接零线电量分析0516..doc VIP
- 2025年乡村医生招聘考试试题题及答案.docx VIP
原创力文档

文档评论(0)