解题代码
int GetHeight(BinTree BT) {
int max = 1;
int a = 1;
reGetHeight(BT,&max,a);
return max;
}
void reGetHeight(BinTree BT, int * max, int a) {
if (!BT) {
*max = 0;
return;
}
if (BT->Left) {
int b = a + 1;
*max = *max > b ? *max : b;
reGetHeight(BT->Left, max, b);
}
if (BT->Right) {
int c = a + 1;
*max = *max > c ? *max : c;
reGetHeight(BT->Right, max, c);
}
}
测试结果
问题整理
1.递归函数传入指针时要特别注意。