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