冒泡排序笔记

         public static void main(string[] args){

          int[] arr = {5,6,8,1,2,7,3};

         for(int num :arr){

         System.out.print("排序之前的数组:"+num);

      }

  for(int i=0;i<arr.length-1i++){

    for(int j = 0;j<arr.length-1-i;j++){

       if(arr[j]>arr[j+1]){

          int temp = arr[j];

          arr[j] = arr[j+1];

         arr[j+1] = temp;

      }    

  }

}

System.out.println("排序后的数组为:");
for(int num:arr){
System.out.print(num+" ");
}

       }

原文地址:https://www.cnblogs.com/guolsblog/p/10401542.html