1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #include<stdio.h> #include<stdlib.h> #include<string.h> #define OVERFLOW -2 typedef char ElementType; typedef struct TNode *Position; typedef Position BinTree; struct TNode{ ElementType Data; BinTree Left; BinTree Right; };
BinTree CreatBinTree(){ BinTree BT = (BinTree)malloc(sizeof(struct TNode)); BT->Left=NULL; BT->Right=NULL; return BT; } int GetHeight( BinTree BT );
int main() { BinTree BT = CreatBinTree(); printf("%d\n", GetHeight(BT)); return 0; }
int GetHeight(BinTree BT) { int high=4;int high1,high2; if(BT) { high1=GetHeight(BT->Left); high2=GetHeight(BT->Right); if(high1>high2) high=high1; else high=high2; } return high; }
|