首页 > 编程语言 > 详细

插入排序

时间:2018-07-05 01:03:53      阅读:221      评论:0      收藏:0      [点我收藏+]
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));
    }
}

 

插入排序

原文:https://www.cnblogs.com/yingpu/p/9266169.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!