对于他们已经给好的代码,然后递归调用函数就可以,
#include <stdio.h>
#include <stdlib.h>
typedef char ElementType;
typedef struct TNode *Position;
typedef Position BinTree;
struct TNode{
ElementType Data;
BinTree Left;
BinTree Right;
};
BinTree CreatBinTree(); /* 实现细节忽略 */
int GetHeight( BinTree BT );
int main()
{
BinTree BT = CreatBinTree();
printf("%d\n", GetHeight(BT));
return 0;
}
int max(int a,int b)
{
if(a > b)
return a;
return b;
}
int GetHeight( BinTree BT )
{
if(BT == NULL)
return 0;
else return 1+ max(GetHeight(BT->Left),GetHeight(BT->Right));
}