选择排序 java代码

 1 public class Paixu_choice {
 2     int[] a=new int[] {8,5,7,9,1,6,7,4,2,6};
 3     public static void main(String[] args) {
 4         Paixu_choice h=new Paixu_choice();
 5         h.go();
 6     }
 7     public void go(){
 8         int out,in,min;
 9         for(out=0;out<a.length-1;out++){
10             min=out;
11             for(in=out+1;in<a.length;in++){
12                 if(a[in]<a[min]){
13                     min=in;
14                 }
15             }
16             change(min,out);
17         }
18         display();
19     }
20     public void change(int x,int y){
21         int    tempp=a[x];
22         a[x]=a[y];
23         a[y]=tempp;
24     }
25     public void display(){
26         for(int i=0;i<a.length;i++){
27             System.out.print(a[i]);
28         }
29     }
30 
31 }

 

posted on 2015-12-15 08:28  shortail  阅读(148)  评论(0编辑  收藏  举报