Preorder traversal code
Anonymous
firstly, find the path from root to child bool getPathFromRoot(Node *treeNode, int desvalue, vector &path) { path.push_back(treeNode) ; if( treeNode->value == desvalue ) return true ; bool lvalue = false , rvalue = false ; if( treeNode->left!=NULL && getPathFromRoot(treeNode->left, desvalue, path) ) { lvalue = true ; } if( treeNode->right!=NULL && getPathFromRoot(treeNode->right, desvalue, path) ) { rvalue = true ; } if ( !rvalue && !lvalue ) { path.pop_back() ; return false ; } else return true ; } then compare these two paths.
Check out your Company Bowl for anonymous work chats.