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

插入排序法学习笔记

时间:2015-05-20 18:03:01      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:

代码:

 1 public class test3
 2 {
 3     public static void insertionSort(int [] a)
 4     {
 5       int i,j,t;
 6       for(i=1;i<a.length;i++)
 7         {
 8           t=a[i];
 9           j=i-1;
10           while(j>=0&&t<a[j])
11             {
12                a[j+1]=a[j];
13                j--;
14            }
15           a[j+1]=t;
16 
17         }
18     
19     }
20 
21     public static void main(String[] args) 
22     {
23         int []a={5,4,3,2,1};
24         insertionSort(a);
25         for(int i=0;i<a.length;i++)
26         {
27                 System.out.println(a[i]);    
28         }
29 
30     }
31 }

运行结果:

技术分享

 

插入排序法学习笔记

标签:

原文地址:http://www.cnblogs.com/gugibv/p/4517568.html

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