public class T035 public static int oneElemSort int int int if length

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class T035 {
public static int[] oneElemSort(int[]a, int i, int j) {
if (j == a.length - i - 2) {
return a;
}
else {
int c = 1;
if (a[j] > a[j + 1]) {
c = a[j];
a[j] = a[j + 1];
a[j + 1] = c;
}
return oneElemSort(a, i, j + 1);
}
}
public static int[] sort(int[]a, int i) {
if (i == a.length - 1) {
return a;
}
else {
return sort(oneElemSort(a, i, 0), i + 1);
}
}
public static void main(String[] args) {
int [] s = sort(new int[]{4, 5, 2, 7}, 0);
for (int i = 0; i < s.length; i++) {
System.out.println(s[i]);
}
}
}