数据结构-冒泡排序

ぐ巨炮叔叔 提交于 2019-11-30 06:09:06
 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 }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!