冒泡排序

public class adf {
public static void main(String[] args) {
int[] a={3,1,5,34,16,47,23,13};
int temp=0;
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length-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]);
}
}

}
....................................................
package forken;
public class asd {
public static void pop_sort(int[] a){ //void换成int[]
int temp=0;
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length-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++) { //、去掉换成reture a;
System.out.println(a[i]);
}
}
public static void main(String[] args) {
int[] a={3,1,5,34,16,47,23,13};
asd.pop_sort(a); //去掉换成 int[] array=asd.pop_sort(a);
//加上 for(int i=0;i // system.out.println(array[i]);
// }
}

}

你可能感兴趣的:(冒泡排序)