// Name :- Bakul Gupta
// Email-id :- bakulgupta11@gmail.com
#include<bits/stdc++.h>
using namespace std;
struct Node
{
int key;
Node *left,*right;
Node(int x)
{
left=NULL;
right=NULL;
key=x;
}
};
int height(Node *root)
{
if(root==NULL)
return 0;
else
{
int l=height(root->left);
int r=height(root->right);
return 1 + max(l,r);
}
}
int main()
{
Node *root=new Node(10);
root->left=new Node(20);
root->right=new Node(30);
root->left->left=new Node(40);
root->left->right=new Node(50);
cout<<"\n Height of the tree is :- "<<height(root)<<endl;
return 0;
}
Comments
Post a Comment