首页 > 代码库 > Bubble Sort

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

//

// }

 

}

}

Bubble Sort