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

📄 bitrdept.c

📁 《数据结构》教材源程序,可以让你轻松的根据教材学习数据结构
💻 C
字号:
#include<stdio.h>
#include<stdlib.h>
typedef char datatype;
typedef struct node            /*二叉树结点定义*/
 {
  datatype data;
  struct node *lchild,*rchild;
  }bintnode;
typedef bintnode *bintree;
void createbintree(bintree *t)       
{/*按照前序遍历的顺序建立一棵给定的二叉树*/
 char ch;
 if ((ch=getchar())==' ')
      *t=NULL;
      else {
	  *t=(bintnode *)malloc(sizeof(bintnode));
	  (*t)->data=ch;
	  createbintree(&(*t)->lchild);
	  createbintree(&(*t)->rchild);
      }
 }
int depth(bintree t)   /*返回二叉树的高度*/
{ int h,lh,rh;
  if (t==NULL) h=0;    /*处理空二叉树的情况*/
  else  {  lh=depth(t->lchild);  /*求左子树的高度*/
           rh=depth(t->rchild);  /*求右子树的高度*/
           if (lh>=rh) h=lh+1;   /*求二叉树t的高度*/
           else  h=rh+1;
         }
  return h;
}

main()
{ bintree root;
  int high;
  createbintree(&root);
  getchar();
  high=depth(root) ;
  printf("the depth of the tree is %d",high);
}
  

⌨️ 快捷键说明

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