title: I am implementing set(MySet) using custom MyNode(Singly linked list). I am having trouble in making union
body: <pre><code>public class MyNode {
      Object element;
      MyNode nextNode;
      public MyNode(Object element) {
          this.element = element;
      }
      public MyNode() {}
  }
  public class Myset {
      int size = 0;
      MyNode head;
      MyNode tail;
      public void Insert(Object o) {
          MyNode node = new MyNode(o);
          if (tail == null) {
              head = node;
              tail = node;
          } else {
              tail.nextNode = node;
              tail = node;
          }
          size++;
      }
      public Myset Union(Myset a) {
      /*
       * case1 a is empty return currentSet
       * case2 a is non empty 
       *       create a variable temp1=a
       *       check for all members of a whether they are a member of currentSet. Delete those from temp1 which are members of currentSet.
       *       add each element of temp1 to currentSet
       *       return currentSet 
       * 
       */
      }
  }
  </code></pre>
  
  <p>So my question is what should i return as <code>currentSet</code>?</p>