Guys i always have this doubt.Please tell me whether stack frames allocated for each recursive call will be cleared if we return in the middle of a recursive call?
On Tue, Jul 12, 2011 at 10:22 PM, Don <dondod...@gmail.com> wrote: > // Similar to other suggestions, but without tail recursion. > > ptr search(ptr root, int value) > { > ptr result = 0; > while(root && !result) > { > result = (root->tag == value) ? root : search(root->left, > value); > root = root->right; > } > return result; > } > > On Jul 12, 8:28 am, anonymous procrastination <opamp1...@gmail.com> > wrote: > > Hello, > > > > Suppose you have to search a particular node in a binary tree. > > The code is quite simple. Pick up any traversal and see if any node > > matches the value. > > Doubt I have is that how to pull out of the recursive function at the > > instant node is found. > > In iterative algos we use a break. > > Here I can use a global flag variable. But any other bettr way of > > doing this? > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@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. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@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.