首页 > 其他 > 详细

计算员工的重要度

时间:2019-11-07 11:04:48      阅读:81      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

/**
 * 深度遍历的一个简单例子
 *
 */
public class EmployeeImportance {
    
    private static int res = 0;
    private static Employee employee;
    public static void main(String[] args) {
        Employee e1 = new Employee(1, 5, Arrays.asList(2,3));
        Employee e2 = new Employee(2, 3, null);
        Employee e3 = new Employee(3, 3, null);
        int total = getImportance(Arrays.asList(e1,e2,e3), 1);
        System.out.println(total);
        
    }
    
    
    public static int getImportance(List<Employee> emps, int id) {
        for(Employee emp : emps) {
            if(emp.id == id) {
                employee = emp;
                res += emp.value;
                break;
            }
        }
        List<Integer> list = employee.subordinates;
        if(list != null) {
            for(Integer i : list) {
                getImportance(emps, i);
            }
        }
        return res;
    }
    
}

class Employee {
    
    int id;
    int value;
    List<Integer> subordinates;

    public Employee(int id, int value, List<Integer> subordinates) {
        super();
        this.id = id;
        this.value = value;
        this.subordinates = subordinates;
    }
}

 

 

计算员工的重要度

原文:https://www.cnblogs.com/moris5013/p/11810728.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!