package lrs.visitor; import lrs.*; /** * Sorts by splitting the host into two sublists, sorts the sublists, then * merges the sorted sublists. */ public class MergeSorter implements IAlgo { public static final MergeSorter Singleton = new MergeSorter (); private MergeSorter() { } /** * @param host * @param input not used. * @return null */ public Object nullCase(LRStruct host, Object input) { return null; // there is nothing to sort } /** * @param host * @param input not used. * @return null. */ public Object nonNullCase(LRStruct host, Object input) { return host.getRest().execute(MergeSortHelper.Singleton, host); } public static void main(String[] args) { LRStruct l1 = new LRStruct (); System.out.println ("l1: " + l1); System.out.println ("Merge sort l1..."); l1.execute(MergeSorter.Singleton, null); System.out.println ("l1: " + l1); l1.insertFront (new Integer (-9)); l1.insertFront (new Integer (15)); l1.insertFront (new Integer (263)); l1.insertFront (new Integer (-72)); l1.insertFront (new Integer (0)); l1.insertFront (new Integer (48)); /* */ System.out.println ("l1: " + l1); System.out.println ("Merge sort l1..."); l1.execute(MergeSorter.Singleton, null); System.out.println ("l1: " + l1); } }