// this is the first lab problem, please understand this solution is provided as an
// example only, since there are many other ways in which you could have approached
// this problem as the TAs should have discussed them with you in lab/office hours

import java.util.*;

public class Second { // this is problem R15.18
  public static <T> LinkedList<T> union (LinkedList<T> List1, LinkedList<T> List2){
    LinkedList<T> temp = new LinkedList<T>(List1);
    ListIterator<T> iter2 = List2.listIterator();
    
    while(iter2.hasNext()){
      T s = iter2.next();
      if(!List1.contains(s)){
        temp.add(s);
      }
    }
    return temp;
  }
  public static <T> LinkedList<T> intersection (LinkedList<T> List1, LinkedList<T> List2){  
    LinkedList<T> temp = new LinkedList<T>(List1);
    ListIterator<T> iter2 = temp.listIterator();
    while(iter2.hasNext()){
      T s = iter2.next();
      if(!List2.contains(s)){
        temp.remove(s);
      }
    }
    return temp;
  }    
    
    
  public static void main(String[] args){
    LinkedList<String> staff1 = new LinkedList<String>();
    staff1.add("a");
    staff1.add("b");
    staff1.add("c");
    LinkedList<String> staff2 = new LinkedList<String>();
    staff2.add("a");
    staff2.add("b");
    staff2.add("d");   
    System.out.println(union(staff1,staff2).toString());
    System.out.println(intersection(staff1,staff2).toString());
  }
}