boolean printAllAncestors(BinaryTreeNode root,BinaryTreeNode node){
if(root == null){
return false;
}
if(root.getLeft() == node || root.getRight() == node || printAllAncestors(root.getLeft(),node) ||
printAllAncestors(root.getRight(),node)){
System.out.println(root.getData());
return ture;
}
return false
}
Print all ancestor nodes of a node in the binary tree
Guess you like
Origin blog.csdn.net/weixin_37632716/article/details/114680044
Recommended
Ranking