代码语言:javascript复制
int get_height(Node *node) {
int left, right, max;
if (node) {
left = get_height(node->left);
right = get_height(node->right);
max = left > right ? left : right;
return max 1;
} else {
return 0;
}
}
int get_max(Node *node) {
if (node) {
int ml = get_max(node->left);
int mr = get_max(node->right);
int root = node->data;
int max = ml > mr ? ml : mr;
return max > root ? max : root;
} else {
return -1;
}
}