首页 > 编程语言 > 详细

插入排序 java代码

时间:2015-12-15 08:58:42      阅读:168      评论:0      收藏:0      [点我收藏+]
 1 public class Paixu_charu {
 2     int[] a=new int[] {8,5,7,9,1,6,7,4,2,6};
 3     public static void main(String[] args) {
 4         Paixu_charu h=new Paixu_charu();
 5         h.go();
 6     }
 7     public void go(){
 8         int out=1;
 9         int in;
10         int temp;
11         while(out<10){
12             temp=a[out];
13             in=out;
14             while(in>0&&a[in-1]>temp){
15                 a[in]=a[in-1];
16                 in--;
17             }
18             a[in]=temp;
19             out++;
20         }
21         display();
22     }
23 
24     public void display(){
25         for(int i=0;i<a.length;i++){
26             System.out.print(a[i]);
27         }
28     }
29 }

 

插入排序 java代码

原文:http://www.cnblogs.com/shortail/p/5047062.html

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