首页 > 代码库 > 数组的冒泡排序方法展示

数组的冒泡排序方法展示

package cn.itcast;public class pubbleSort {	public static void main(String[] args) {		int[] arr = { 84, 65, 95, 8, 63, 54, 25, 68, 47, 77, 58, 54, 69, 55, 58, 4, 5, 55, 48, 87, 45, 58, 54, 12, 25,				49 };		for (int i = 0; i < arr.length; i++) {			System.out.print(arr[i] + "  ");			if (i == arr.length - 1) {				System.out.println("");			}		}		System.out.println("--------------------------" );		// 冒泡排序方法		for (int i = 0; i < arr.length - 1; i++) {			for (int x = 0; x < arr.length - 1-i; x++) {				if (arr[x] > arr[x + 1]) {					// 数值交换					int a = arr[x];					arr[x] = arr[x + 1];					arr[x + 1] = a;				}			}	     }		for (int i = 0; i < arr.length; i++) {			System.out.print(arr[i] + "  ");			if (i == arr.length - 1) {				System.out.println("");			}		}	}}

  

数组的冒泡排序方法展示