//Question 1 //Part A: Code trace //myList = a, b, c, d, e, f String temp = myList.get(1); // temp = b myList.add(1, myList.get(4)); // myList = a, e, b, c, d, e, f myList.add(4, temp); //myList = a, e, b, c, b, d, e, f //Part B static void swap(int i, int j, List myList){ String temp = myList.get(i); myList.add(i, myList.get(j)); myList.remove(i+1); myList.add(j,temp); myList.remove(j+1); } //Question 2 public static ListADT union(List list1, ListADT list2) throws BadListException { ListADT returnListADT = new ArrayList(); String string; if ((list1 == null) || (list2 == null)) { throw new BadListException(); } if ((list1.isEmpty()) && (list2.isEmpty())) { return returnListADT; } Iterator iter1 = list1.iterator(); Iterator iter2 = list2.iterator(); while(iter1.hasNext()){ string = iter1.next(); //If the return list doesn't already have an element, add it. if (!slowContains(string, returnListADT)) { returnListADT.add(string); } } while(iter2.hasNext()){ string = iter2.next(); if (!slowContains(string, returnListADT)) { returnListADT.add(string); } } return returnListADT; } private static boolean slowContains(String string, ListADT list){ Iterator iter = list.iterator(); while(iter.hasNext()){ String currentString = iter.next(); if (string.equals(currentString)) { return true; } } return false; } public class BadListException extends Exception { public BadListException() { super(); } public BadListException(String message){ super(message); } }