【问题标题】:Print out all the ancestor node names for a given node in a tree in java?打印出java中树中给定节点的所有祖先节点名称?
【发布时间】:2016-11-23 10:54:04
【问题描述】:

在一家公司中,有一位 CEO,在他下面有一个经理和员工的等级,假设最低级别的员工打印出他所有上级的名字,一直到 CEO。如何在 Java 中实现这一点?

【问题讨论】:

    标签: java recursion tree


    【解决方案1】:

    因为你没有给我们任何代码,这是我们可以给你的最好的伪代码的一般概念:

    function String drawHierarchy(Employee employee){
        print "Employee name {}" + employee.getName();
        if(employee.getParent() != null){
            return drawHierarchy(employee.getParent());  
        } 
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多