-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sort.java
64 lines (41 loc) · 997 Bytes
/
Sort.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Sort {
public static void main(String[] args) {
int[] array = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
// for (int x: array){
// System.out.println(x);
// }
// for (i = 0; i < array.length; i++) {
// val1 = array[0];
// for (j = i + 1; j < array.length; j++) {
// if (array[j] < array[i]) {
// pos1 = array[j];
// // array[i + ] = val1;
// }
// }
// pos2 = array[i];
// array[i] = array[j];
// array[j] = pos2;
// }
sort(array);
}
public static void sort(int[] array) {
int cur_pos;
int min_pos;
int scan_pos;
int temp;
for (cur_pos = 0; cur_pos < array.length; cur_pos++) {
min_pos = cur_pos;
for (scan_pos = cur_pos + 1; scan_pos < array.length; scan_pos++) {
if (array[scan_pos] < array[min_pos]) {
min_pos = scan_pos;
}
temp = array[min_pos];
array[min_pos] = array[cur_pos];
array[cur_pos] = temp;
}
}
for (int x: array){
System.out.println(x);
}
}
}