二叉树的应用_数据结构课程设计(10页).doc





《二叉树的应用_数据结构课程设计(10页).doc》由会员分享,可在线阅读,更多相关《二叉树的应用_数据结构课程设计(10页).doc(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-二叉树的应用_数据结构课程设计-第 10 页信息科学与技术学院数据结构课程设计报告题目名称:二叉树的应用专业班级:计算机科学与技术学生姓名:陈 杰学生学号:200808261指导教师:高 攀完成日期:2010-04目 录1、课程设计的目的、课程设计题目、题目要求2课程设计的目的3课程设计的题目3题目要求32课程设计的实验报告内容:43课程设计的原程序代码:44运行结果165. 课程设计总结216参考书目221课程设计的目的1.1课程设计的目的:通过以前的学习以及查看相关资料,按着题目要求编写程序,进一步加强对编程的训练,使得自己掌握一些将书本知识转化为实际应用当中.在整个程序中,主要应用的是
2、链表,但是也运用了类.通过两种方法解决现有问题.课程设计的题目: 二叉树的应用题目要求:1. 建立二叉树的二叉链表存储算法2. 二叉树的先序遍历,中序遍历和后序遍历输出3. 非递归的先序遍历,中序遍历4. 二叉树的层次遍历5. 判断此二叉树是否是完全二叉树6. 二叉树的左右孩子的交换2课程设计的实验报告内容:7. 通过递归对二叉树进行遍历。二叉树的非递归遍历主要采用利用队进行遍历。此后的判断此二叉树是否是完全二叉树也才采用队,而二叉树的左右孩子的交换则采用的是一个简单的递归。3课程设计的原程序代码:#includeusing namespace std;#define MAXSIZE 100i
3、nt sign=0;void menu();typedef struct BiTNodechar data;BiTNode *left_child,*right_child;BiTNode,*BiTree;int CreateBiTree(BiTree &T)/创建二叉树 char ch; coutch; if(ch=#) T=NULL; else if(!(T=new BiTNode) coutdata=ch; CreateBiTree(T-left_child);/create leftchild CreateBiTree(T-right_child); /create rightchil
4、d return 1;/判断此树是否是完全二叉树int LevelOrder1(BiTree &T)BiTree stackMAXSIZE;BiTreep;int front,rear;front=-1,rear=0;stackrear=T;while(rear!=front)front+;p=stackfront;if(p-left_child=NULL)&(p-right_child)sign=1;if(p-left_child)rear+;stackrear=p-left_child;if(p-right_child)rear+;stackrear=p-right_child;retur
5、n 1;void Output(BiTree &T) /输出二叉树if(!T) cout空树!n;return ; /空树coutdataleft_child) Output(T-left_child); /输出左子树if(T-right_child)Output(T-right_child);/输出右子树int Depth(BiTree &T) /求树深int i,j;if(!T) return 0;i = Depth(T-left_child);j = Depth(T-right_child);return (ij?i:j) + 1;int Node(BiTree &T)/求结点数if(!
6、T) return 0;return 1+Node(T-left_child)+Node(T-right_child);int Leaf(BiTree &T) /求叶子结点if(!T) return 0;if(!T-left_child&!T-right_child) return 1;/仅有根结点return Leaf(T-left_child)+Leaf(T-right_child);/返回叶子结点的数目void PreOrder(BiTree &T) /先序遍历算法 DLRif(!T) return ; /递归调用的结束条件coutdataleft_child);/先序递归遍历T的左子树
7、PreOrder(T-right_child);/先序递归遍历T的右子树void InOrder(BiTree &T)/中序遍历算法 LDRif(!T) return ;InOrder(T-left_child);coutdataright_child);void PostOrder(BiTree &T)/后序遍历算法 LRDif(!T) return ;PostOrder(T-left_child);PostOrder(T-right_child);coutdata ;/非递归先序遍历int NRPreOrder(BiTree &T)BiTree stack100,p;int top;if(
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 二叉 应用 数据结构 课程设计 10

限制150内