package com.matao.sorting;

import edu.princeton.cs.algs4.StdOut;

/**
 * Created by matao on 8/14/16.
 */
public abstract class BaseSort {
    public abstract void sort(Comparable[] a);

    protected boolean lessThan(Comparable v, Comparable w) {
        return v.compareTo(w) < 0;
    }

    protected void exchange(Comparable[] a, int i, int j) {
        Comparable tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }

    protected void show(Comparable[] a) {
        for (int i = 0; i < a.length; i++) {
            StdOut.print(a[i] + " ");
        }
        StdOut.println();
    }

    public boolean isSorted(Comparable[] a) {
        for (int i = 0; i < a.length; i++) {
            if (lessThan(a[i], a[i + 1])) {
                return false;
            }
        }
        return true;
    }
}

@@ -650,33 +650,33 @@
    for (int i = 
-0
+1
 ; i %3C a.length; 
@@ -717,17 +717,17 @@
 i%5D, a%5Bi 
-+
+-
  1%5D)) %7B%0A

fix incorrect isSorted() logic