冒泡排序

来源:互联网 发布:淘宝店铺商品详情模板 编辑:程序博客网 时间:2024/06/06 02:30
package Chapter1;
//冒泡排序
public class BubbleSort {
public BubbleSort(int a[]){
int temp = 0;
for(int i = 0 ; i < a.length - 1 ; i++){
for(int j = 0 ; j < a.length - 1 - i ; j++){
if(a[j] > a[j+1]){
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
for(int i = 0 ; i < a.length ; i++)
System.out.println(a[i]);
}
public static void main(String [] args){
int[] a = {9,8,6,7,3,5,4,2,8,0};
new BubbleSort(a);
}
}
0 0
原创粉丝点击