Here is the Iterative function: //Function to compute height of a binary tree iteratively
int GetHeight(struct node *root) { //NULL root check if(root==NULL) return 0; int hl=0; // Height of Left subtree int hr=0; // Height of Right subtree struct node *templ=root; while(temp1 && templ->left) { templ= templ->left; hl++; } while(root && root->right) { root=root->right; hr++; } return (hl>hr ?(hl+1):(hr+1)); } Thanks and Regards, Ashish On Thu, Jul 8, 2010 at 9:18 PM, jalaj jaiswal <jalaj.jaiswa...@gmail.com>wrote: > @ above he asked iterative . > .. use a stack to eliminate recursion ... > > > On Thu, Jul 8, 2010 at 9:00 PM, Anand <anandut2...@gmail.com> wrote: > >> height(struct *node) >> { >> int left_height; >> int right_height; >> if(node == NULL) >> return 0; >> else >> left_height = height(node->left); >> right_height = height(node->right); >> return (1+ max(left_height, right_height)); >> >> >> } >> >> On Thu, Jul 8, 2010 at 2:46 AM, sharad <sharad20073...@gmail.com> wrote: >> >>> write algo to find hieght of BINARY tree ITERATIVELY >>> >>> -- >>> 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<algogeeks%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > With Regards, > Jalaj Jaiswal > +919026283397 > B.TECH IT > IIIT ALLAHABAD > > -- > 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.