//树的存储结构
//双亲存储结构
typedef struct
{
int data;//结点的值
int parent;//指向双亲位置的伪指针
} PTree[maxsize];
//孩子存储结构
typedef struct node
{
int data;//结点的值
struct node *sons[maxsize];//指向孩子结点
}TSonNode;
//孩子兄弟链存储结构
typedef struct tnode
{
int data;
struct tnode *hp;//指向下一个兄弟结点
struct tnode *vp;//指向第一个孩子结点
} TSBNode;
//求树的高度的递归算法
int Treeheight(TBSNode *t)
{
TSBNode *p;
int m,max = 0;
if (t == NULL)
return 0;//空树返回0
else if (t -> vp == NULL)//没有孩子结点返回1
return 1;
else
{
p = t->vp;//指向第一棵子树
while (p != NULL)//从所有孩子结点中找一个高度最大的孩子结点
{
m = Treeheight(p);
if (max < m)
max = m;
p = p->hp;//继续求其他兄弟结点的高度
}
return (m+1);//加上根结点
}
}
原文:http://www.cnblogs.com/tong1487/p/4008266.html