冒泡排序-java实现

package bubblesort;


public class BubbleSort {
public static void main(String[] args) {
long[] a = { 22, 34, 1, 23, 55, 23 };
System.out.println("排序前顺序:");
for (int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println();
bubbleSort(a);
System.out.println("排序后顺序:");
for (int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");


}


public static void bubbleSort(long[] array) {
int size = array.length;
int in, out;
for (out = size - 1; out > 1; out--) {
for (in = 0; in < out; in++) {
if (array[in] > array[in + 1]) {
long temp = array[in];
array[in] = array[in + 1];
array[in + 1] = temp;
}


}
}
}
}

你可能感兴趣的:(冒泡排序-java实现)