数据结构-冒泡排序

 1 package com.datastack.search;
 2 
 3 import java.util.Arrays;
 4 
 5 //冒泡排序
 6 public class BubSearch {
 7     public static void main(String[] args) {
 8         int[] arr = {6,1,8,23,3,5,6,9,12};
 9         int temp;
10         for(int i=0; i<arr.length; i++){
11             for(int j=0; j<arr.length-1-i; j++){
12                 if(arr[j]>arr[j+1]){
13                     temp = arr[j];
14                     arr[j] = arr[j+1];
15                     arr[j+1] = temp;
16                 }
17             }
18         }
19         System.out.println(Arrays.toString(arr));
20     }
21 }

 

posted @ 2019-09-22 09:52  az1l3l  阅读(151)  评论(0编辑  收藏  举报