#include<stdio.h>
typedef int ElemType;
typedef struct node            //定义二叉树结点结构
{
    ElemType data;
    struct node *lchild;
    struct node *rchild;
}BTNode;

typedef struct                //1.定义双亲结构储存类型
{
    ElemType data;
    int parent;                //指向双亲的位置
}ptree[MaxSize];

typedef struct node            //2.孩子链储存结构的结点类型
{
    ElemType data;
    stuct node *sons[MaxSons];
}tsonnode;

typedef struct tnode        //3.兄弟链存储结构中结点类型
{
    ElemType data;            //结点的值
    struct tnode *hp;        //指向兄弟
    struct tnode *vp;        //指向孩子结点
}tbsnode;

int treeheight(tsbnode *t)    //求树的高度的递归模型
{
    tsbnode *p;
    int m,max=0;
    if(t==null)
        return 0;
    else if(t->vp==NULL)
        return 1;
    else;
    else
    {
        {
            p=t->vp;
            while(p!=NULL)
            {
                m=treeheight(p);
                if(max<m)max=m;
                p=p->hp;
            }
            return(m+1);
        }
    }

 

posted on 2012-05-11 11:24  C's  阅读(218)  评论(0编辑  收藏  举报