⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch5_60.c

📁 数据结构( C语言版) 讲义daima数据结构( C语言版) 讲义daima
💻 C
字号:
#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 %d\n",high);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -