1. 程式人生 > >一、插入排序(insertion sort)

一、插入排序(insertion sort)

per end urn turn ext integer ret spa any

    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); } } }

一、插入排序(insertion sort)