冒泡排序

时间:2020-07-22 10:50:17   收藏:0   阅读:59
 2 
 3 public class MyBubbleSort {
 4     public static void main(String[] args) {
 5         int num[] = {10,8,33,54,1,6,12,43,32,27};
 6         bubbleSort(num);
 7         for (int i = 0; i < num.length; i++) {
 8             System.out.print(num[i] + " ");
 9         }
10     }
11 
12     private static void bubbleSort(int[]num){
13         for (int i = 0; i < num.length ; i++) {
14             for (int j = i+1; j < num.length ; j++) {
15                 if (num[i]>num[j]){
16                     int temp = num[i];
17                     num[i] = num[j];
18                     num[j] = temp;
19                 }
20             }
21         }
22     }
23 }

 

原文:https://www.cnblogs.com/zz-1120-wtenlb/p/13358957.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!