/** * Sorts the host list in ascending order. Assumes host list contains Integer objects.
Selection sort algorithm:
Case list is empty: do nothing
Case list is not empty:
    Find the minimum element of the list.
    Move it to the front of the list.
    Recur on the rest of the list.
* @author Dung X. Nguyen - Copyright 1999 - All rights reserved. */ public class SelectSort implements IAlgo { public final static SelectSort Singleton = new SelectSort (); private SelectSort() { } /** * @param host * @param input * @return */ public Object nullCase(QFList host, Object input) { return null; } /** * @param host * @param input * @return */ public Object nonNullCase(QFList host, Object input) { host.insertFront(host.execute(RemMin.Singleton,null)); return host.getRest().execute(this, null); } public static void main(String[] args) { QFList l1 = new QFList (); l1.insertFront (new Integer (-9)); l1.insertFront (new Integer (15)); l1.insertFront (new Integer (263)); l1.insertFront (new Integer (-72)); System.out.println ("l1: " + l1); System.out.println ("Sorting l1..."); l1.execute(SelectSort.Singleton, null); System.out.println ("l1: " + l1); try { System.out.println ("Press Enter to quit..."); System.in.read (); } catch (Exception e) { } } }