Files

38 lines
964 B
Java
Raw Permalink Normal View History

2017-03-18 22:17:22 -05:00
// Author: Rodney Shaghoulian
2018-07-27 16:45:56 -07:00
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
2017-03-18 22:17:22 -05:00
import java.util.Scanner;
public class Solution {
2017-03-24 00:02:30 -05:00
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);
}
2017-03-18 22:17:22 -05:00
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;
2017-03-24 00:02:30 -05:00
printArray(array);
2017-03-18 22:17:22 -05:00
}
private static void printArray(int[] array) {
for (int num: array) {
System.out.print(num + " ");
}
System.out.println();
2017-03-24 00:02:30 -05:00
}
2017-03-18 22:17:22 -05:00
}