最简单的冒泡排序算法

public class Sort {


public static void main(String[] args) {

//冒泡排序算法
int[] ch = {1,4,6,85,74,87,52,14,23,98,510,42};
for(int i=0;i for(int j=0;j
if(ch[j]>ch[j+1]){
    int temp=0;
    temp = ch[j];
    ch[j] = ch[j+1];
ch[j+1] = temp;
}
}
}
   for(int cha:ch){
       System.out.print(cha+" ");
}
System.out.println();

//选择排序
int[] a = {1,4,6,85,74,87,52,14,23,98,510,42};
for(int i=0;i for(int j=i+1;j if(a[i]>a[j]){
int temp=a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(int cha:a){
System.out.print(cha+" ");
}
}
}

你可能感兴趣的:(java)