data=ch; bt"/> data=ch; bt"/>
首页 求二叉树深度算法

求二叉树深度算法

举报
开通vip

求二叉树深度算法求二叉树深度算法 #include #include typedef struct node { char data; struct node *lchild,*rchild; }JD; JD *crt_bt_pre(JD *bt) { char ch; printf("ch="); scanf("%c",&ch); getchar(); if(ch==' ') bt=NULL; else { bt=(JD *)malloc(sizeof(JD)); bt->data=ch; bt...

求二叉树深度算法
求二叉树深度算法 #include #include typedef struct node { char data; struct node *lchild,*rchild; }JD; JD *crt_bt_pre(JD *bt) { char ch; printf("ch="); scanf("%c",&ch); getchar(); if(ch==' ') bt=NULL; else { bt=(JD *)malloc(sizeof(JD)); bt->data=ch; bt->lchild=crt_bt_pre(bt->lchild); bt->rchild=crt_bt_pre(bt->rchild); } return(bt); } void treedepth(JD *bt,int *l,int *h) { int l1=0,l2=0,h1=0,h2=0; if(bt!=NULL) { (*l)++; if (*l>*h) *h=*l; treedepth(bt->lchild,&l1,&h1); treedepth(bt->rchild,&l2,&h2); if (h1>h2) *h=*h+h1; else *h=*h+h2; } } void main() { /* ABC00DE0G00F000 */ JD *head=NULL; int level=0,high=0; head=crt_bt_pre(head); treedepth(head,&level,&high); printf("depth of tree is %d\n",high); }
本文档为【求二叉树深度算法】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_729658
暂无简介~
格式:doc
大小:12KB
软件:Word
页数:0
分类:互联网
上传时间:2017-09-28
浏览量:34