import java.util.Arrays;
import junit.framework.TestCase;
/**
* 冒泡排序
*
* @author jsczxy2
*
*/
public class BubbleSort extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
}
private void swap(int[] a, int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
private void bubbleSort(int[] a) {
int i, j;
for (i = 0; i < a.length - 1; i++) {
for (j = i + 1; j <= a.length - 1; j++) {
if (a[i] > a[j])
swap(a, i, j);
}
}
}
public void test() {
int a[] = { 4, 2, 6, 12, 7, 9, 1 };
bubbleSort(a);
System.out.println(Arrays.toString(a));
}
}