Implements a function to check whether a tree is balanced. Balancing means that the distance between any two leaf nodes of the tree and the root node is not greater than 1.
Struct node {node () {value = 1; left = right = NULL;} int value; node * left; node * Right ;}; int max = 0; int min = 0; int maxheight (node * root) {If (root = NULL) {return 0;} int leftheight = maxheight (root-> left) + 1; int rightheight = maxheight (root-> right) + 1; return leftheight> rightheight? Leftheight: rightheight;} int minheight (node * root) {If (root = NULL) {return 0;} int leftheight = minheight (root-> left) + 1; int rightheight = minheight (root-> right) + 1; if (root-> left = NULL) {return rightheight;} else if (root-> right = NULL) {return leftheight;} else {return leftheight <rightheight? Leftheight: rightheight;} bool isbalanced (node * root) {int max = maxheight (Root); int min = minheight (Root); If (max-min <= 1) {return true;} return false ;}