/**
* @author WenQiang Wu
* @version Dec 28, 2009
*/
public class BubbleSort {
/**
* bubble sort
*
* @param value
*/
public static void bubbleSort(int[] value) {
for (int i = 0; i < value.length; i++) {
for (int j = 0; j < value.length - i - 1; j++) {
if (value[j] > value[j + 1]) {
int temp = value[j];
value[j] = value[j + 1];
value[j + 1] = temp;
}
}
}
}
/**
* display result
*
* @param value
*/
public static void display(int[] value) {
for (int i = 0; i < value.length; i++) {
System.out.print(value[i] + " ");
}
}
/**
*
* @param args
*/
public static void main(String[] args) {
int[] value = { 12, 8, 3, 59, 132, 1236, 3400, 8, 352, 37 };
bubbleSort(value);
display(value);
}
}
冒泡排序
最新推荐文章于 2023-06-06 09:14:05 发布