Add a method

LispList merge(LispList other)

to the LispList interface of Exercise P15.10 that returns the length of the list. Implement the method in the EmptyList and NonEmptyList classes. When merging two lists, alternate between the elements, then add the remainder of the longer list. For example, merging the lists with elements 1 2 3 4 and 5 6 yields 1 5 2 6 3 4.

Complete the following files:

EmptyList.java

NonEmptyList.java

Use the following files:

LispList.java

public interface LispList
{
   LispList NIL = new EmptyList();
   boolean isEmpty();
   Object head();
   LispList tail();
   LispList cons(Object obj);
   LispList merge(LispList lp);
}

LispListTester.java

public class LispListTester
{
   public static void main(String[] args)
   {
      LispList list1 = new EmptyList();

      LispList list2 = new NonEmptyList(1, new NonEmptyList(2, new NonEmptyList(3,
         new EmptyList())));

      LispList list3 = LispList.NIL.cons("E").cons("D").cons("C").cons("B").cons("A");

      LispList list4 = list3.merge(list2);
      System.out.println(list4);
      System.out.println("Expected: A 1 B 2 C 3 D E");

      System.out.println(list2.merge(list3));
      System.out.println("Expected: 1 A 2 B 3 C D E");
      
      System.out.println(list1.merge(list2));
      System.out.println("Expected: 1 2 3");

      System.out.println(list2.merge(list1));
      System.out.println("Expected: 1 2 3");

      System.out.println(list2.merge(list2));
      System.out.println("Expected: 1 1 2 2 3 3");
      
      System.out.println("[" + list1.merge(list1) + "]");
      System.out.println("Expected: []");      
   }
}