http://www.daniweb.com/code/snippet216621.html

decent code


Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Fri, Jul 9, 2010 at 3:35 PM, UMESH KUMAR <kumar.umesh...@gmail.com>wrote:

>
>
> * find height of BINARY tree ITERATIVELY??*
>
>
> //**************************************************************************************************************************
>
>  * Algorithm:-*
>
>        First create a  STACK of Apropriate Size of Bnode pointer type
>        and perform a PUSH operation (Starting from Root of the Tree) ,and
> then inceament one in the Level of the
>        Tree and as root=root->left until we get NULL.
>        if we get NULL ,check that TOP <0
>        if  TOP< 0
>       then break ,Because Stack is Empty,Otherwise
>       if encreamented  Level more than currently Height then
>       Height=Level.
>       perform POP Operation from the Stack and store in Root.
>       if Root->right does note exit then Decreament one  from the level
>       and finaly Root=Root->right.
>
>
> *Just  a  C -code  *:-
>
>       int  height(struct bnode* root)
>          {
>            int  top=heigh=lev= -1
>            bnode *stack[MAX]
>
>             while(1)
>                 {
>                  while(root)
>                   {
>                          if(top>MAX-1)
>                            {
>                           print->"Stack is full"
>                           break
>                            }
>                     stack[++top]=root //  PUSH in Stack
>                     lev ++
>                     root=root->left
>                   }
>                if(top<0)
>               break;
>              if(heigh>lev)
>                heigh=lev
>
>               root=stack[top--] //Stack is POP
>               if(root->right==NULL)
>               lev --
>               root=root->right
>            }
>     return height;
> }
>
>
> Umesh kumar
>  MCA  from
> University of Delhi.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to