package com.niewj.ds;
public class Sort {
/**
* bubble sort
*
* @param ia
* 需要排序的数组
*/
public static void bubbleSort(int[] ia) {
int i = ia.length;
int temp;
while (i > 0) {
for (int j = 0; j < i - 1; j++) {
if (ia[j] > ia[j + 1]) {
temp = ia[j];
ia[j] = ia[j + 1];
ia[j + 1] = temp;
}
}
i--;
}
}
public static void printArr(int[] ia) {
for (int a : ia) {
System.out.print(a + " ");
}
}
public static void main(String[] args) {
// 等待排序数组
int[] ia = { 4, 64, 2, 98, 7, -32, 0, 996, 43, 58, -32323, 84, 86, 8, 9 };
// 冒泡排序
bubbleSort(ia);
// 打印排序后结果
printArr(ia);
}
}