java冒泡排序

代码
1 //此程序属转载
2  public class BubbleSort {
3 public static void main(String[] args){
4 int[] sort={9,5,8,6,3};
5 Sort(sort);
6 for(int i=0;i<sort.length;i++)
7 System.out.print(sort[i]+" ");
8 }
9 public static void Sort(int[] sort){
10 int temp;
11 for(int i=0;i<sort.length;i++){
12 for(int j=0;j<sort.length-i-1;++j)
13 if(sort[j]>sort[j+1]){
14 temp=sort[j];
15 sort[j]=sort[j+1];
16 sort[j+1]=temp;
17 }
18 }
19 }
20 }

 

posted @ 2010-05-29 09:36  莫萧  阅读(294)  评论(0编辑  收藏  举报