Yup dudes I agree it was a wrong program I have put the
proper indentation without proper braces and that makes the code
incorrect.
The correct program would be :
int getheight ( node *p )
{
if ( p==NULL )
return 0;
else
{
rh = getheight ( p->right );
all the three statements following else shud be inside else block.
On 4/18/07, pramod negi <[EMAIL PROTECTED]> wrote:
>
> I think this always return height 1. isn't it
>
> On 4/17/07, BiGYaN <[EMAIL PROTECTED]> wrote:
> >
> >
> > We will be calling the function like :
> > height = getheight(root);
I think this always return height 1. isn't it
On 4/17/07, BiGYaN <[EMAIL PROTECTED]> wrote:
>
>
> We will be calling the function like :
> height = getheight(root);
>
> and here's the function defination :
> int getheight ( node *p )
> {
>if ( p==NULL )
>return 0;
>else
>rh
We will be calling the function like :
height = getheight(root);
and here's the function defination :
int getheight ( node *p )
{
if ( p==NULL )
return 0;
else
rh = getheight ( p->right );
lh = getheight ( p->left );
return ( (lh>rh ? lh : rh)+1 );
}
--~-
getHt(node *n)
> {
> if (n)
return ( max(getHt(n->left) + 1, getHt(n->right) +1);
else
return 0;
}
>
> On 4/16/07, Virag Dhulia <[EMAIL PROTECTED]> wrote:
> >
> > HI Experts,
> >
> > I want to calculate the height of a binary tree recursively, any help
> > will be appreciat
if u know the number of elements (n)
height = ln n should do the trick
On 4/17/07, Virag Dhulia <[EMAIL PROTECTED]> wrote:
>
> HI Experts,
>
> I want to calculate the height of a binary tree recursively, any help will
> be appreciated
>
> --
> A man with dreams is never alone
> >
>
--~--~---
getHt(node *n)
{
if (n)
}
On 4/16/07, Virag Dhulia <[EMAIL PROTECTED]> wrote:
>
> HI Experts,
>
> I want to calculate the height of a binary tree recursively, any help will
> be appreciated
>
> --
> A man with dreams is never alone
> >
>
--~--~-~--~~~---~--~~
You