冒泡排序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了冒泡排序相关的知识,希望对你有一定的参考价值。

public class BubbleSortDemo {
	public static void main(String[] args) {
		int[] ints = {5,9,6,4,3,5,8,1,2,4};
		sort(ints);
		for (int i : ints) {
			System.out.print(i + " ");
		}

	}

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

}


以上是关于冒泡排序的主要内容,如果未能解决你的问题,请参考以下文章