package cn.aust.zyw.demo; /** * Created by zyw on 2016/2/8. * quick-sort */ public class Selection { public static void sort(int [] a){ int N=a.length; for(int i=0;i<N;i++){ int min=i; for(int j=i+1;j<N;j++){ if(less(a[j],a[min])) min=j; exch(a,i,min); } } } private static boolean less(int v, int w){ if(v<w) return true; return false; } private static void exch(int[] a,int i,int j){ int t=a[i];a[i]=a[j];a[j]=t; } private static void show(int[] a){ for(int i=0;i<a.length;i++){ System.out.printf(a[i]+" "); } } public static boolean isSorted(int[] a){ for(int i=1;i<a.length;i++) if(less(a[i],a[i-1])) return false; return true; } public static void main(String args[]){ int a[]={20,5,14,3,63,1,55,11,0}; sort(a); show(a); } }