CH5_60.C
上传用户:lgb298
上传日期:2013-03-22
资源大小:1025k
文件大小:1k
- #include <alloc.h>
- #include <stdio.h>
- 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 %dn",high);
- }