import java.util.ArrayList; import java.util.List; import sort.InsertionSort; import sort.QuickSort; import sort.Sort; import sort.SortableComparableData; import sort.SortableData; import sort.SortableDataWithStatistics; import sort.SortableDataWithTracer; import sort.SwapableList; /* * Created on 24 oct. 2004 * */ /** * @author baudon * */ public class TestSort { public static void sortAndPrint(SortableData sd, Sort sort) { sort.doSort(sd); for (int i = 0; i < sd.size(); ++i) { System.out.print(sd.get(i) + " "); } System.out.println(); } public static void initList(List l, T[] a) { l.clear(); for (T t : a) { l.add(t); } } public static void main(String[] args) { Sort isort = new InsertionSort(); Sort qsort = new QuickSort(); List ls = new ArrayList(); initList(ls, args); SortableDataWithStatistics sdws = new SortableDataWithStatistics( new SortableDataWithTracer(new SortableComparableData(new SwapableList(ls)))); sortAndPrint(sdws, isort); System.out.println("Stats: " + sdws.getSwapStat() + " swap, " + sdws.getCompareStat() + " compare"); initList(ls, args); sdws = new SortableDataWithStatistics( new SortableDataWithTracer(new SortableComparableData(new SwapableList(ls)))); sortAndPrint(sdws, qsort); System.out.println("Stats: " + sdws.getSwapStat() + " swap, " + sdws.getCompareStat() + " compare"); } }