Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include "tree.h"
- int TreeHeight(Tree t) {
- if (t == NULL) return 0;
- int l = TreeHeight(t->left);
- int r = TreeHeight(t->right);
- return 1 + l + r;
- }
- bool TreeIsPerfectlyBalanced(Tree t) {
- if (t == NULL) return true;
- int l = TreeHeight(t->left);
- int r = TreeHeight(t->right);
- if (l - r < -1 || l - r > 1)
- return false;
- else
- return TreeIsPerfectlyBalanced(t->left)
- && TreeIsPerfectlyBalanced(t->right);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement