Write a recursive C function to calculate the height of a binary tree.

bookmark

  1. int countHeight(struct node* t)  
  2. {  
  3.     int l,r;  
  4.     if(!t)  
  5.         return 0;  
  6.     if((!(t->left)) && (!(t->right)))  
  7.         return 0;  
  8.     l=countHeight(t->left);  
  9.     r=countHeight(t->right);  
  10.     return (1+((l>r)?l:r));  
  11. }