欢迎来到天天文库
浏览记录
ID:43364913
大小:241.09 KB
页数:16页
时间:2019-09-30
《二叉树基本操作及哈夫曼编译译码系统实现》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验报告(2015/2016学年第2学期〉课程名称数据结构A实验名称二叉树的基本操作及哈夫曼编译译码系统的实现实验时间2016年4月13日指导单位计算机科学与技术系指导教师骆健学生姓名班级学号学院係)管理学院专业信息管理与信息系统实验一:二叉树基本操作一、问题陈述在二叉链表上实现二叉树的建立、删除、求髙度、求子叶节点数、左右交换、遍历等操作。二、概要设计建立不同函数,分别实现二叉树的各项基本运算。三、详细设计1.层次结构:文件一共需要5个函数。文件中包含各个函数函数的声明。分别是:statuscreat
2、ebitree(bitree*t);statuspreordertraverse(bitreet);intheight(bitreet);voidswap(bitree*t);voidleafcounts(bitreet);2.核心算法:statuscreatebitree(bitree*t)intch=0;cin>>ch;if(ch==0)(*t)=NULL;else(*t)=(bitree)malloc(sizeoF(binode));(*t)->data=ch;createbitree(&(*t)
3、->lchild);createbitree(&(*t)->rchild);}returnOK;statuspreordertrauerse(bitreet)iF(t)cout«t->data«Bi11;preordertrauerse(t->lchild);preordertrauerse(t->rchild);returnOK;}elsereturnOK;intheight(bitreet)lchild)*1;hr=
4、height(t->rchild)+1;return(hl>hr?hl:hr);uoidswap(bitree*t)bitreep;if(*t?=NULL)
lchild;(»t)->lchild=(»t)->rchild;(»t)->rchild=p;swap(&(*t)->lchild);swap(&(*t)->rchild);uoidleaFcounts(bitreet)lchild==NULL&&t->rchild==NULL)leafcount**;l
5、eafcounts(t->lchild);leafcounts(t->rchild);主函数uoidnain()6、xi,«endl;cout«,e^:计算二良树迪髙度,,<7、ndl;cout«iB5:树进行左右翻转cout«-,0:逋岀-«endl;cout«M请输入:,*«endl;cin»choice;switch(choice)break;case2:if(?treecrea8、ted)_cout<<••先序遍历顺序:・・<leafcounts(bt);cout<<"树的叶子数:*l«leaFco9、unt«endl;cout<10、已经翻转!!!"<<“(11;break;case0:leaue=TRUE;break;>}vihile(?leaue);cout«i,再见i,«endl;开始Z先序遍历求子叶数求高度进行翻转退出结束四、程序代码#include
6、xi,«endl;cout«,e^:计算二良树迪髙度,,<7、ndl;cout«iB5:树进行左右翻转cout«-,0:逋岀-«endl;cout«M请输入:,*«endl;cin»choice;switch(choice)break;case2:if(?treecrea8、ted)_cout<<••先序遍历顺序:・・<leafcounts(bt);cout<<"树的叶子数:*l«leaFco9、unt«endl;cout<10、已经翻转!!!"<<“(11;break;case0:leaue=TRUE;break;>}vihile(?leaue);cout«i,再见i,«endl;开始Z先序遍历求子叶数求高度进行翻转退出结束四、程序代码#include
7、ndl;cout«iB5:树进行左右翻转cout«-,0:逋岀-«endl;cout«M请输入:,*«endl;cin»choice;switch(choice)break;case2:if(?treecrea
8、ted)_cout<<••先序遍历顺序:・・<leafcounts(bt);cout<<"树的叶子数:*l«leaFco
9、unt«endl;cout<10、已经翻转!!!"<<“(11;break;case0:leaue=TRUE;break;>}vihile(?leaue);cout«i,再见i,«endl;开始Z先序遍历求子叶数求高度进行翻转退出结束四、程序代码#include
10、已经翻转!!!"<<“(11;break;case0:leaue=TRUE;break;>}vihile(?leaue);cout«i,再见i,«endl;开始Z先序遍历求子叶数求高度进行翻转退出结束四、程序代码#include
此文档下载收益归作者所有