资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
#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)/前序遍历 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() bitree *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 *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);
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号