程序填空题:Hight of a Binary Tree
The function Height is to find the height of a binary tree T. The height of a leaf node is defined to be 0.
The tree structure is defined as the following:
typedef struct Node *PtrToNode;
struct Node{
int Data;
PtrToNode Left, Right;
};
typedef PtrToNode Tree;
Please fill in the blanks.
c++
int Height( Tree T )
{
int left_H, right_H;
if (T==NULL) return ;
left_H = Height(T->Left);
;
return ( max(left_H, right_H) + 1 );
}
答案:
第1空:-1
第2空:right_H = Height(T->Right)
The tree structure is defined as the following:
typedef struct Node *PtrToNode;
struct Node{
int Data;
PtrToNode Left, Right;
};
typedef PtrToNode Tree;
Please fill in the blanks.
c++
int Height( Tree T )
{
int left_H, right_H;
if (T==NULL) return ;
left_H = Height(T->Left);
;
return ( max(left_H, right_H) + 1 );
}
答案:
第1空:-1
第2空:right_H = Height(T->Right)