int depthOfTree(TreeNode *root) { int depth = 0; if (root == NULL) return depth; if(root->left == NULL && root->right == NULL) return ++depth; return (max(depthOfTree(root->left),depthOfTree(root->right)) + 1); }
bool isBalanced(TreeNode* root) { if(root == NULL) return true; if(!isBalanced(root->left) || !isBalanced(root->right)) return false; return (abs(depthOfTree(root->left)-depthOfTree(root->right)) <= 1); }
/* Node Deletion Of Binary Tree */ int Delete(tree **root,int data) { tree *t1,*t2; if(IsEmptyTree(*root)){ printf("Tree Empty !\n"); return 0; } t1=findNode(root,data); t2=depthOfTree(root); if(t1 == NULL){ printf("Not Exist Node : %d\n",data); return 0; } t1->data=t2->data; t1=t2; free(t2); return data; }