二叉树C++编程问题.doc

上传人:re****.1 文档编号:549206387 上传时间:2023-12-26 格式:DOC 页数:3 大小:39KB
返回 下载 相关 举报
二叉树C++编程问题.doc_第1页
第1页 / 共3页
二叉树C++编程问题.doc_第2页
第2页 / 共3页
二叉树C++编程问题.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《二叉树C++编程问题.doc》由会员分享,可在线阅读,更多相关《二叉树C++编程问题.doc(3页珍藏版)》请在金锄头文库上搜索。

1、#includetypedef char elemtype;const int maxsize=1024;struct bitree elemtype data; bitree *lchild,*rchild;bitree *create()/建二叉树 bitree *T; elemtype x; cinx; if (x=0) T=NULL; else T=new bitree; T-data=x; cout请输入datalchild=create(); cout请输入datarchild=create(); return T;void preorder(bitree *root)/前序遍历

2、bitree *p; p=root; if(p!=NULL) coutdatalchild); preorder(p-rchild); void inorder(bitree *root)/中序遍历 bitree *p; p=root; if(p!=NULL) inorder(p-lchild); coutdatarchild); void postorder(bitree *root)/后序遍历 bitree *p; p=root; if(p!=NULL) postorder(p-lchild); postorder(p-rchild); coutdata ; void main1() bi

3、tree *T; int k; do coutnnnn; coutttt*n; coutttt* 1-前序遍历 *n; coutttt* 2-中序遍历 *n; coutttt* 3-后序遍历 *n; coutttt* 0-返回主菜单 *n; coutttt*n; coutk; if(k=1) coutn 此树前序遍历的顺序:; preorder(T); else if(k=2) cout(n 此树中序遍历的顺序:); inorder(T); else if(k=3) coutn 此树后序遍历的顺序:; postorder(T); while(k!=0);void main() bitree *

4、T; int k; do coutnnnnntttt 二叉树的基本操作系统n; coutttt*n; coutttt* 1-建 二 叉 树 *n; coutttt* 2-查 找 二 叉 树 *n; coutttt* 3-遍 历 二 叉 树 *n; coutttt* 4-二叉树 的深 度 *n; coutttt* 5-二叉树结点个数 *n; coutttt* 0- 返 回 *n; coutttt*n; coutk; if(k=1) coutn 请输入二叉树的根结点(0为空结点):; T=create(); else if(k=2) else if(k=3) main1(); else if(k=4) int h=treehigh(T); coutn 此二叉树的深度为:h; else if (k=5) int c=count(T); coutn此二叉树结点的个数为:c; while(k!=0);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号