日拱一卒(四十八)

冒泡排序:

public class BubbleSort {
	public static void main(String[] args) {
		sort(new int[] { 5, 3, 2, 9, 2, 0, 4 });
	}

	public static void sort(int[] a) {
		int temp = 0;
		for (int i = a.length - 1; i > 0; --i) {
			for (int j = 0; j < i; ++j) {
				if (a[j + 1] < a[j]) {
					temp = a[j];
					a[j] = a[j + 1];
					a[j + 1] = temp;
				}
			}
		}
	}
}

你可能感兴趣的:(android)