Create an employee directory structure that stores employee information for a company. Include manager direct reports.
Implement the following functions:
- AddEmployee
- Adds an employee to the company directory
- RemoveEmployee
- Removes an employee from the company directory
- GetDirectReports
- Returns a list of the direct reports for a given manager
- GetEmployee
- Returns the employee information
这道题要求设计一个员工目录结构,核心是同时维护“员工信息”和“上下级关系”。实现时通常会用哈希表按员工 ID 快速定位员工对象,并在员工对象中保存经理引用、直属下属列表等信息,这样 AddEmployee、RemoveEmployee、GetEmployee 和 GetDirectReports 都能高效完成。删除员工时要特别注意同步更新其经理的下属列表,以及必要时处理直属汇报关系的重连或清理,是这类公司组织结构题的关键。
正文完