I have to maintain a the employee structure of a company. Each employee has associated with it a unique name (no two with the same name) and a level (integer). the level denotes where the person stands in the hierarchy. Level 1 = highest (only 1 employee can be at level 1, but there can be several employees at level i > 1). Each level i employee works under a level i-1 employee, who is his/her immediate boss. Now, given any employee say A, there is/are employees A', A''... such that A works under A', A' works under A'' and so on. I need to create a suitable tree structure.
I need to implement following methods:
addEmployee(new, boss) - new will work immediately under boss
delEmployee(e1, e2) - e1 will be removed and all employees under e1 will now work under e2. (note - e1 and e2 are given to be at the same level)
lowestCommonBoss(e1, e2) - self explanatory
printEmployees() - print names of all employees level wise
Now what i did was i create a node class:
public class Node {
String element;
Node parent;
protected ArrayList<Node> children;
protected int level;
Node(String e) {
this.element = e;
this.parent = null;
this.children = new Arraylist();
this.level = 1;
}
}
Now, what kind of tree structure should i follow? Is this the node i am looking for?