Height of binary tree
/*The tree node has data, left child and right child
struct node
{
int data;
node* left;
node* right;
};
*/
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
int height(node * root)
{
if(root==NULL)return 0;
else
return 1+max(height(root->left),height(root->right));
}
Comments
Post a Comment