-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.java
More file actions
42 lines (36 loc) · 737 Bytes
/
A.java
File metadata and controls
42 lines (36 loc) · 737 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
37
38
39
40
41
42
public class A {
public static void main(String[] args) {
int arr[]= {5,2,4,6,3,1};
int n=arr.length;
for(int i=1;i<n;i++)
{
int key=arr[i];
int j=i-1;
while(j>=0 && arr[j]>key)
{
arr[j+1]=arr[j];
j=j-1;
}
arr[j+1]=key;
System.out.println(i+"iteration");
System.out.print("{");
for(int e=0;e<n;e++)
{
if(e==(n-1))
System.out.print(arr[e]+"}");
else
System.out.print(+arr[e]+",");
}
System.out.println();
}
System.out.println("Final result of sorting is");
System.out.print("{");
for(int k=0;k<n;k++)
{
if(k==(n-1))
System.out.print(arr[k]+"}");
else
System.out.print(+arr[k]+",");
}
}
}