File tree 1 file changed +54
-0
lines changed
1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ import java .util .Scanner ;
4
+
5
+ public class Insertion {
6
+ public static void main (String [] args ) {
7
+
8
+
9
+ Scanner sc =new Scanner (System .in );
10
+ System .out .print ("Enter Number of Elements: " );
11
+ int n =sc .nextInt ();
12
+ int a []=new int [n ];
13
+ for (int i =0 ;i <n ;i ++)
14
+ {
15
+ a [i ]=sc .nextInt ();
16
+ }
17
+ System .out .println (" " );
18
+ System .out .println ("Elements" );
19
+ System .out .println (" " );
20
+
21
+ for (int i =0 ;i <a .length ;i ++)
22
+ {
23
+ System .out .print (a [i ]+" \t " );
24
+ }
25
+
26
+ for (int i =1 ;i <a .length ;i ++)
27
+ {
28
+ int temp =a [i ];
29
+ int j =i -1 ;
30
+
31
+ while (j >=0 && temp <=a [j ])
32
+ {
33
+ a [j +1 ]=a [j ];
34
+ j =j -1 ;
35
+ }
36
+
37
+ a [j +1 ]=temp ;
38
+ }
39
+
40
+
41
+ System .out .println (" \n " );
42
+ System .out .println (" " );
43
+ System .out .println ("Sorting Elements" );
44
+ System .out .println (" " );
45
+ for (int i =0 ;i <a .length ;i ++)
46
+ {
47
+ System .out .print (a [i ]+" \t " );
48
+ }
49
+
50
+ }
51
+
52
+
53
+ }
54
+
You can’t perform that action at this time.
0 commit comments