首页 > 编程语言 > 详细

冒泡排序

时间:2017-06-15 16:16:40      阅读:322      评论:0      收藏:0      [点我收藏+]
package 数组;

public class BubbleSort {

	public static void main(String[] args) {
		int[] array = { 63, 4, 24, 1, 3, 15 };
		BubbleSort sorter = new BubbleSort();
		sorter.sort(array);

	}

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

	public void showArray(int[] array) {
		for (int i : array) {
			System.out.println(">" + i);
		}
		System.out.println();
	}

}


本文出自 “为梦想奋斗” 博客,请务必保留此出处http://holger.blog.51cto.com/7969271/1937096

冒泡排序

原文:http://holger.blog.51cto.com/7969271/1937096

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!