首页 > 其他 > 详细

Bubble Sort

时间:2016-09-23 14:52:34      阅读:202      评论:0      收藏:0      [点我收藏+]

/**

*

*

@author a496006

*

*/

public

class BubbleSort {

 

// Bubble order

public static void main(String[] args) {

 

int k;

Integer[] a = { 2, 1, 6, 5, 4, 3 };

 

for (int i = 0; i < a.length-1; i++) {

 

for (int j = 0; j < a.length-i-1; j++) {

 

if (a[j] < a[j+1]) {

 

k = a[j];

a[j] = a[j+1];

a[j+1] = k;

 

}

 

}

 

}

 

// The below 2 "for cycles" have same functionality

for (Object obj : a) {

System.out.println(obj);

 

}

 

// for (int i = 0; i < a.length; i++) {

//

// System.out.println(a[i]);

//

// }

 

}

}

Bubble Sort

原文:http://www.cnblogs.com/mabel/p/5899696.html

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