阅读背景:

C语言实现基本数据结构之二叉树

来源:互联网 
#include <stdio.h>
#include <stdlib.h>
typedef struct tree{
    int data;
    struct tree *lchild,*rchild;
}node,*bitree;
void creat(bitree *t){
    int value;
    scanf("%d",&value);
    if(value==-1)
        *t=NULL;
    else{
        *t=(bitree)malloc(sizeof(node));
        (*t)->data = value;
        creat(&(*t)->lchild);
        creat(&(*t)->rchild);
    }
}
void hpost(bitree t){
    if(t==NULL);
    else{
      hpost(t->lchild);
      printf("%d",t->data);
      hpost(t->rchild);
    }
}
int gethigh(bitree t){
    if(t==NULL){
        return 0;
    }else{
        int len = gethigh(t->lchild);
        int ren = gethigh(t->rchild);
        if(len>ren){
            return len+1;
        }else{
             return ren+1;
        }
    }
}
int main(){
   bitree t;
   //构建一个二叉树
  creat(&t);
  //中序遍历
   hpost(t);
   //二叉树深度
   int a=gethigh(t);
   printf("二叉树的高度为%d",a);
  return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: