title: Storing hierarchical structure of a company
body: <p>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.</p>
  
  <p>I need to implement following methods:</p>
  
  <p><strong>addEmployee(new, boss)</strong> - new will work immediately under boss</p>
  
  <p><strong>delEmployee(e1, e2)</strong> - 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)</p>
  
  <p><strong>lowestCommonBoss(e1, e2)</strong> - self explanatory</p>
  
  <p><strong>printEmployees()</strong> - print names of all employees level wise</p>
  
  <p>Now what i did was i create a node class:</p>
  
  <pre><code>public class Node {
      String element;
      Node parent;
      protected ArrayList&lt;Node&gt; children;
      protected int level;
  
      Node(String e) {
      this.element = e;
      this.parent = null;
      this.children = new Arraylist();
      this.level = 1;
      }
  }
  </code></pre>
  
  <p>Now, what kind of tree structure should i follow? Is this the node i am looking for?</p>