-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathInsertionSort-Part1.java
More file actions
33 lines (27 loc) 路 704 Bytes
/
Copy pathInsertionSort-Part1.java
File metadata and controls
33 lines (27 loc) 路 704 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
import java.util.Scanner;
public class Solution {
/* Tail starts here */
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int s = in.nextInt();
int[] ar = new int[s];
for(int i=0;i<s;i++){
ar[i]=in.nextInt();
}
int i = s-2;
int temp = ar[s-1];
while(i>=0 && ar[i]>temp){
ar[i+1] = ar[i];
i--;
printArray(ar);
}
ar[i+1] = temp;
printArray(ar);
}
private static void printArray(int[] ar) {
for(int n: ar){
System.out.print(n+" ");
}
System.out.println("");
}
}