Bubble Sort

/**

*

*

@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]);

//

// }

 

}

}

posted @ 2016-09-23 13:27  mabelfdm  阅读(104)  评论(0编辑  收藏  举报