Skip to content

Instantly share code, notes, and snippets.

@duyet
Created June 19, 2014 11:25
Show Gist options
  • Select an option

  • Save duyet/fcf53894a3558a7f8d1a to your computer and use it in GitHub Desktop.

Select an option

Save duyet/fcf53894a3558a7f8d1a to your computer and use it in GitHub Desktop.
Xuất những nút có chiều cao nhánh trái bằng chiều cao nhánh phải
int max(int a, int b) {
return (a > b) ? a : b;
}
int getHeight(TREE T) {
if (T == NULL) return 0;
return 1 + max(getHeight(T->left), getHeight(T->right));
}
void print(TREE T) {
if (T == NULL) return;
print(T->left);
if (getHeight(T->left) > 0 && getHeight(T->left) == getHeight(T->right)) {
cout << T->value << " ";
}
print(T->right);
}
// Cấu trúc của node tự sửa lại cho khớp nha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment