/**
* 冒泡排序
* @param a
*/
public void BubbleSort(int[] a){
int temp = 0;
System.out.println("排序之前:");
for(int m=0; m<a.length; m++){
System.out.print(a[m]+"\t");
}
System.out.println();
for(int i=0; i<a.length; i++){
for(int j=0; j<a.length-1-i; j++){
if(a[j] > a[j+1]){
temp = a[j+1];
a[j+1] = a[j];
a[j] = temp;
}
}
}
System.out.println("排序之后:");
for(int n=0; n<a.length; n++){
System.out.print(a[n]+"\t");
}
}
/**
* @param args
*/
public static void main(String[] args) {
TestSort ts = new TestSort();
// 冒泡排序
int a[] = {49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,99,98,54,56,17,18,23,34,15,35,25,53,51};
ts.BubbleSort(a);
}
冒泡排序
最新推荐文章于 2022-07-11 19:15:30 发布