冒泡排序
/**
* 冒泡排序
* @author yangzi
*
*/
public class Sort {
public static void maoPao(int[] arr){
int ib = 0;
for(int i = 1; i < arr.length; i++){
boolean f = false;
for(int j = 0; j < arr.length - i; j++){
if(arr[j] > arr[j+1]){
ib = arr[j];
arr[j] = arr[j+1];
arr[j+1] = ib;
f = true;
}
}
if(!f){
return;
}
}
}
public static void main(String[] args) {
int[] arr = {12,45,67,23,21,989,231,11,60,2,5,6};
maoPao(arr);
System.out.println(arr.length);
System.out.println("-------------");
for(int i : arr){
System.out.println(i);
}
}
}