# compile program #include #define true 1 #define false 0 struct bTREE{ int height ; int left; int right; }; int height(bTREE *root){ // it's the same depth // the maximum distance between the root node of the tree and the leaf node of the tree. if (root == NULL) return -1; else{ int leftHeight , rightHeight ; leftHeight = height(reinterpret_cast(root->left)); rightHeight =height (reinterpret_cast(root->right)); // calling them recursively if (rightHeight>leftHeight) return rightHeight+1; else leftHeight; } return 0; } int balanced(bTREE *root){ int rightDegree; int leftDegree; if (root==NULL) return 0; if (root->left==NULL && root->right==NULL) return 0; rightDegree = height(root->right); leftDegree = height(root->left); if (balanced(leftDegree-rightDegree && root->left && root->right)) return true; else return false; }