int Diameter(TreeNode t, int* height)
{
int lh = 0, rh = 0;
int leftD = 0, rightD = 0;
if(t == NULL)
{
*height = 0;
return 0; /* diameter is also 0 */
}
leftD = Diameter (root->left, &lh);
rightD = Diameter (root->right,&rh);
/* Height of current node is max of heights of left and
right subtrees plus 1*/
*height = max(lh, rh) + 1;
return max(lh + rh + 1, leftD, rightD);
}