为了账号安全,请及时绑定邮箱和手机立即绑定

冒泡排序怎么弄

冒泡排序怎么弄

慕莱坞1111902 2017-10-19 16:15:52
查看完整描述

1 回答

已采纳
?
yanrun

TA贡献317条经验 获得超240个赞

public class BubbleSort {

	public static void bubbleSort() {
		int a[] = { 49, 38, 65, 97, 76, 13, 27, 49, 78, 34, 12, 64, 5, 4, 62,
				99, 98, 54, 56, 17, 18, 23, 34, 15, 35, 25, 53, 51 };
		int temp = 0;
		for (int i = 0; i < a.length - 1; i++) {
			for (int j = 0; j < a.length - 1 - i; j++) {
				if (a[j] > a[j + 1]) {
					temp = a[j];
					a[j] = a[j + 1];
					a[j + 1] = temp;
				}
			}
		}
		for (int i = 0; i < a.length; i++)
			System.out.print(a[i] + " ");
	}
	
	public static void main(String[] args) {
		bubbleSort();
	}

}


查看完整回答
2 反对 回复 2017-10-19
  • 1 回答
  • 1 关注
  • 1192 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信