package com.kilophone.classcontent;
/**
* @author Administrator 冒泡排序
*
*/
public class TestBubbleSort {
public static void bubbleSort(int arr[]) {
for (int i = 1; i < arr.length; i++) {
for (int j = 0; j < arr.length - i; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = temp;
}
}
loopArray(arr);
System.out.println();
}
}
public static void loopArray(int arr[]) {
for (int a : arr) {
System.out.print(a + "\t");
}
}
public static void main(String[] args) {
int arr[] = { 5, 8, 9, 2, 7 };
bubbleSort(arr);
}
}
BubbleSort
最新推荐文章于 2018-07-17 16:52:22 发布