格式了一下. package untitled7;public class Lixin {
public static void main(String[] args) {
int[] a = new int[10];
for (int i = 0; i < 10; i++) {
a[i] = i * i - 10 * i + 25;
System.out.println(a[i]);
}
System.out.println(); sort(a, 0, a.length - 1); for (int i = 0; i < 10; i++) {
System.out.println(a[i]);
} } public static void sort(int[] x, int k, int n) {
int i = 0;
int temp = x[0];
int j = x.length - 1;
while (i < j) {
while ( (i < j) && (x[j] >= temp)) {
--j;
}
while ( (i < j) && (x[i] <= temp)) {
++i;
}
swap(x, i, j);
}
swap(x, 0, i);
sort(x, 0, i - 1);
sort(x, i + 1, x.length - 1);
} public static void swap(int[] c, int m, int n) {
int temp = 0;
temp = c[m];
c[m] = c[n];
c[n] = temp;
}
}
public static void main(String[] args) {
int[] a = new int[10];
for (int i = 0; i < 10; i++) {
a[i] = i * i - 10 * i + 25;
System.out.println(a[i]);
}
System.out.println(); sort(a, 0, a.length - 1); for (int i = 0; i < 10; i++) {
System.out.println(a[i]);
} } public static void sort(int[] x, int k, int n) {
int i = 0;
int temp = x[0];
int j = x.length - 1;
while (i < j) {
while ( (i < j) && (x[j] >= temp)) {
--j;
}
while ( (i < j) && (x[i] <= temp)) {
++i;
}
swap(x, i, j);
}
swap(x, 0, i);
sort(x, 0, i - 1);
sort(x, i + 1, x.length - 1);
} public static void swap(int[] c, int m, int n) {
int temp = 0;
temp = c[m];
c[m] = c[n];
c[n] = temp;
}
}
请告之,
不过用java.util.arrays.sort就可以直接排了啊,不用写这么多
Arrays
和Collections