private static void CalculateSalary(Employee employee) { if (visitedEmplyees.Contains(employee.Id)) { return; } if (employee.Subordinates.Count == 0) { employee.Salary = 1; return; } visitedEmplyees.Add(employee.Id); foreach (var subordinate in employee.Subordinates) { CalculateSalary(subordinate); employee.Salary += subordinate.Salary; } }
public void AddSubordinate(Employee employee) { this.Subordinates.Add(employee); }