码迷,mamicode.com
首页 > 编程语言 > 详细

冒泡排序

时间:2016-02-27 01:12:17      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:排序   冒泡   

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;
				}
			}
		}
	}

}


冒泡排序

标签:排序   冒泡   

原文地址:http://pengsaiwei.blog.51cto.com/3071802/1745401

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!