I have to write a non recursive program to print the ancestor (parent of parent) of a given node in a Binary Tree. What logic should I use ?
Use a non recursive sub routine to traverse the binary tree( refer to http://en.wikipedia.org/wiki/Tree_traversal#Implementations) and maintain a stack to store the all parent nodes in that array and whenever you pop from stack suitably pop the element from the stack. Finally when you find the element, second topmost element on the stack would be the ancestor.