-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sort_Insert.java
42 lines (41 loc) · 1.1 KB
/
Sort_Insert.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
import java.util.*;
public class Sort_Insert {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a[] = new int[105];
int b[] = new int[105];
for(int i=0;i<n;i++){
a[i] = in.nextInt();
b[i] = 0;
}
b[0] = a[0];
int index = 1;
int k = 0;
System.out.println("Buoc " + k + ": " + b[0]);
k++;
for(int i=1;i<n;i++){
if(a[i]>b[index-1]){
b[index] = a[i];
// index ++;
}
else{
int x = 0;
for(int j=index;j>0;j--){
b[j] = b[j-1];
if(b[j-1]<a[i]){
x = j;
break;
}
}
b[x] = a[i];
}
index ++;
System.out.print("Buoc "+k+": ");
k++;
for(int j=0;j<index;j++)
System.out.print(b[j]+" ");
System.out.println();
}
}
}