插入排序

import java.util.*;
public class Insert{
    public void getInsert(int[] array){
        if(array == null || array.length == 0) return;
        int j=0;
        for(int i=1;i<array.length;i++){
            int temp = array[i];
            for(j=i;j>0&&(array[j-1]>temp);j--){
                array[j]=array[j-1];
            }
            array[j] = temp;
        }
    }
    public static void main(String[] args){
        int[] array = {9,8,7,6,5,4,3,2,1};
        Insert i = new Insert();
        i.getInsert(array);
        System.out.println(Arrays.toString(array));
    }
}

 

posted @ 2018-07-05 00:41  樱圃  阅读(91)  评论(0编辑  收藏  举报