冒泡排序
时间:2020-07-22 11:34:29
收藏:0
阅读:63
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 }
评论(0)