-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Solution.java
35 lines (31 loc) · 877 Bytes
/
Solution.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
// github.com/RodneyShag
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int s = scan.nextInt();
int[] array = new int[s];
for (int i = 0; i < s; i++) {
array[i] = scan.nextInt();
}
scan.close();
insertIntoSorted(array);
}
public static void insertIntoSorted(int[] array) {
int i = array.length - 1;
int value = array[i];
while (i >= 1 && array[i-1] > value) {
array[i] = array[i-1];
i--;
printArray(array);
}
array[i] = value;
printArray(array);
}
private static void printArray(int[] array) {
for (int num: array) {
System.out.print(num + " ");
}
System.out.println();
}
}