码迷,mamicode.com
首页 > 其他好文 > 详细

Bubble Sort

时间:2016-09-23 14:55:09      阅读:91      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!