-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertSortApp2.java
More file actions
36 lines (28 loc) · 815 Bytes
/
InsertSortApp2.java
File metadata and controls
36 lines (28 loc) · 815 Bytes
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
import java.util.Arrays;
class MyInsertSort2 {
private int[] array = {4, 2, 9, 3, 1, 3, 11, 8};
int[] sort(int[] array) {
int min, in;
min = array[0];
for (int i = 1; i < array.length; i++) {
in = i;
while (in > 0 && array[in] > array[in - 1]){
min = array[in - 1];
array[in - 1] = array[in];
array[in] = min;
in--;
}
}
return array;
}
public int[] getArray() {
return array;
}
}
public class InsertSortApp2 {
public static void main(String[] args) {
MySelectSort2 selectSort2 = new MySelectSort2();
selectSort2.sort(selectSort2.getArray());
System.out.println(Arrays.toString(selectSort2.getArray()));
}
}