5. Diameter of Binary Tree code example
Example: get diameter of binary tree
int getDiameter(TreeNode* root)
{
if(root == NULL)
return(0);
int lheight = getHeight(root->left);
int rheight = getHeight(root->right);
int ldiameter = getDiameter(root->left);
int rdiameter = getDiameter(root->right);
return(max(lheight+rheight+1,max(ldiameter,rdiameter)));
}