程序填空题: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 1.
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 ;
;
right_H = Height(T->Right);
return ( max(left_H, right_H) + 1 );
}
答案:
第1空:0
第2空:left_H = Height(T->Left)
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 ;
;
right_H = Height(T->Right);
return ( max(left_H, right_H) + 1 );
}
答案:
第1空:0
第2空:left_H = Height(T->Left)