您的位置:首页 > 编程语言 > Java开发

java实现冒泡排序

2016-10-08 09:20 218 查看
1 /**
2          * 冒泡排序
3          * @param a
4          * @date 2016-10-8
5          * @author shaobn
6          */
7         public static void bubbleSort(int[] a){
8             int temp = 0;
9             for(int i = 1;i<a.length;i++){
10                 for(int j = 0;j<a.length-i;j++){
11                     if(a[j]>a[j+1]){
12                         temp = a[j];
13                         a[j] = a[j+1];
14                         a[j+1] = temp;
15                     }
16                 }
17             }
18             for(int num:a){
19                 System.out.println(num);
20             }
21         }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: