package chooseSort; import java.util.Arrays; public class Example { public void sort(Comparable[] a){}; /** * 交换 * @param a * @param i * @param j */ public static void exch(Comparable[] a ,int i, int j){ Comparable temp; temp = a[i]; a[i]=a[j]; a[j]=temp; } /** * 比较 * @param a * @param b * @return */ public static boolean less(Comparable a,Comparable b){ return a.compareTo(b)<0; } /** * 显示当前数组 * @param a */ public static void show(Comparable[] a){ System.out.println(Arrays.toString(a)); } /** * 判断数组是否有序 * @param a * @return */ public static boolean isSorted(Comparable[] a){ for(int i =0;i<a.length-1;i++){ if(a[i].compareTo(a[i+1])>0) return false; } return true; } }