title: Finding Diameter of a Tree
body: <p>I have written code for finding the diameter of binary tree. But I am unable to figure out where is it going wrong . The two functions that I have written and their definition are as follows :- </p>
  
  <pre><code>    int btree::diameteroftree(node* leaf)
      { 
       if (leaf==NULL) 
       return 0;
  
       int lheight = hieghtoftree(leaf-&gt;left);
       int rheight = hieghtoftree(leaf-&gt;right);
  
       int ldiameter = diameteroftree(leaf-&gt;left);
       int rdiameter = diameteroftree(leaf-&gt;right);
  
       return max(lheight + rheight + 1,max(ldiameter,rdiameter));
     }
  
  
     int btree::hieghtoftree(node* leaf)
     {
      int left=0,right=0;
      if(leaf==NULL)
      return -1;
      else
      {
       left=hieghtoftree(leaf-&gt;left);
       right=hieghtoftree(leaf-&gt;right);
       if(left &gt; right)
       return left +1;
       else
       return right+1;   
      }
     }
  </code></pre>
  
  <p>I am unable to figure out where am I going wrong here . Can someone let me know ...</p>