// Textbook fragment 11.03 /** * Merges two sorted lists, in1 and in2, into a sorted list in. **/ public static void merge(PositionList in1, PositionList in2, Comparator c, PositionList in) { while (!in1.isEmpty() && !in2.isEmpty()) if (c.compare(in1.first().element(), in2.first().element()) <= 0) in.addLast(in1.remove(in1.first())); else in.addLast(in2.remove(in2.first())); while(!in1.isEmpty()) // move the remaining elements of in1 in.addLast(in1.remove(in1.first())); while(!in2.isEmpty()) // move the remaining elements of in2 in.addLast(in2.remove(in2.first())); }