Print all ancestor nodes of a node in the binary tree

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
}

Guess you like

Origin blog.csdn.net/weixin_37632716/article/details/114680044