概述
冒泡升序排列
代码
package com.lilei.myes.es.pack1114; import java.util.Random; public class bulb_sort { public static void main(String[] args) { Random rand = new Random(); int[] array = new int[10]; for (int i = 0; i < array.length; i++) array[i] = rand.nextInt(100); for (int v : array) System.out.print(v + ","); System.out.println(); sort(array); for (int v : array) System.out.print(v + ","); } static void sort(int[] array){ int end = array.length-1; while(end>0){ int p = 0; while(p + 1<= end){ if (array[p] > array[p+1]){ int tmp = array[p]; array[p]= array[p+1]; array[p+1] = tmp; } p++; } end--; } } }