/**
   * Merge two sorted lists, L1 and L2, into a sorted list L.
   **/
  public static void merge(List L1, List L2, Comparator c, List L) {
    while (!L1.isEmpty() && !L2.isEmpty())
      if (c.compare(L1.first().element(), L2.first().element()) <= 0)
        L.insertLast(L1.remove(L1.first()));
      else
        L.insertLast(L2.remove(L2.first()));
    while(!L1.isEmpty()) // move the remaining elements of L1
      L.insertLast(L1.remove(L1.first()));
    while(!L2.isEmpty()) // move the remaining elements of L2
      L.insertLast(L2.remove(L2.first()));
  }