public Dictionary <string, List <EmployeeComponent> > FindAllEmployees(Dictionary <string, List <EmployeeComponent> > employeesWithPositions = null) { if (employeesWithPositions == null) { employeesWithPositions = new Dictionary <string, List <EmployeeComponent> >(); } if (!employeesWithPositions.ContainsKey(Position)) { List <EmployeeComponent> employees = new List <EmployeeComponent> { this }; employeesWithPositions.Add(Position, employees); } else { employeesWithPositions[Position].Add(this); } IEnumerator iterator = CreateIterator(); bool hasNext = iterator.MoveNext(); while (hasNext) { EmployeeComponent employee = (EmployeeComponent)iterator.Current; employeesWithPositions = employee.FindAllEmployees(employeesWithPositions); hasNext = iterator.MoveNext(); } return(employeesWithPositions); }
public void PrintBackwards() { Dictionary <string, List <EmployeeComponent> > employees = new Dictionary <string, List <EmployeeComponent> >(); _output.Print($"There are hierarchy of company by positions:"); foreach (KeyValuePair <string, List <EmployeeComponent> > keyValue in _root.FindAllEmployees()) { foreach (EmployeeComponent employee in keyValue.Value) { _output.Print($"{employee}"); } } }