一、插入排序(insertion sort)

 

    Public class InsertionSort{
        Public static<AnyType extends Comparable<? Super AnyType>> AnyType[] insertionSort(AnyType[]a){
            intj;
            for(intp=0;p<a.length;p++){
                AnyTypetmp=a[p];
                for( j = p;j > 0 && tmp.compareTo(a[j-1]) < 0;j--){
                a[j]=a[j-1];
                }
                a[j]=tmp;
            }
            returna;
        }
        @Test
        Public void testInsertionSort(){
            Integer[]b={11,23,32,67,21,1};
            Integer[]c=insertionSort(b);
            for(Integers:c){
                 System.out.println(s);
            }
        }
    }

 

posted @ 2019-03-24 21:29  Pure_Java  阅读(406)  评论(0编辑  收藏  举报