sort

package sort;排序

public class Sort3 {
public static void main(String[] args) {
int[] a = { 2, 54, 23, 57, 72, 3, 46, 7, 8, 20, 324, 0, 32, 1 };
UpSort(a);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}class

/*
* 冒泡排序
*/sort

public static void UpSort(int a[]) {
for (int j = 0; j < a.length - 1; j++) {
for (int i = 0; i < a.length - 1 - j; i++) {
if (a[i] > a[i + 1]) {
swap(a, i, i + 1);
}
}
}
}static

private static void swap(int[] a, int i, int j) {
int temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}void

相關文章
相關標籤/搜索