java实现冒泡排序
View Code
1 package com.test.suanfa; 2 3 public class Maopao { 4 public static void main(String[] args) { 5 Maopao sort = new Maopao(); 6 int[] arr= new int[]{7,22,11,5,400,99,20,22,5}; 7 sort.sort(arr); 8 for(int i : arr) 9 System.out.print(i+","); 10 } 11 12 13 public void sort(int[] targetArr){//小到大的排序 14 int temp = 0; 15 for(int i = 0;i<targetArr.length;i++){ 16 for(int j = i+1;j<targetArr.length;j++){ 17 System.out.print(targetArr[i]+"---------"+targetArr[j]+"``````比较转换之后`````"); 18 if(targetArr[i]>targetArr[j]){ 19 temp = targetArr[i]; 20 targetArr[i] = targetArr[j]; 21 targetArr[j] = temp; 22 } 23 for(int k : targetArr) 24 System.out.print(k+","); 25 System.out.println(); 26 } 27 28 } 29 } 30 }
因为年轻,所有没有失败。