(java版)
public class bubbleSort {
static void BubbleSort(int l[]){
int i,j;
boolean exchange = false;
int swap;
for(i = 0; i<l.length-1; i++){
for(j = l.length-1; j>i; j--){
if(l[j] < l[j-1]){
swap = l[j-1];
l[j-1] = l[j];
l[j] = swap;
exchange = true;
}
if(!exchange)
return;
}
}
}
public static void main(String[] args) {
int[] a = {0,2,5,43,32,65,43,21,87,1};
BubbleSort(a);
for(int i = 0; i<a.length; i++)
System.out.print(a[i]+" ");
}
}