码迷,mamicode.com
首页 > 编程语言 > 详细

插入排序--InsertSort

时间:2014-11-05 21:11:10      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   for   sp   div   log   bs   

算法导论,插入排序

public class InsertSort {
    public static double [] sort(double [] num)
    {
        for(int i =1; i<num.length;i++)
        {   
            double temp = num[i];
            int j=i-1;
            while(j>=0 && temp < num[j])
            {
                num[j+1]=num[j];
                j--;
            }
            num[j+1] = temp;
        }
        return num;
    }
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        double num [] ={1.3, 5 ,2, 6.9, 7.8,4.3};
        num = InsertSort.sort(num);
        for(double a:num)
            System.out.print(a+" ");
    }
}

 

插入排序--InsertSort

标签:style   blog   color   ar   for   sp   div   log   bs   

原文地址:http://www.cnblogs.com/wzm-xu/p/4077186.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!