首页 > 编程语言 > 详细

冒泡排序

时间:2016-02-27 01:09:15      阅读:202      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!