forked from mrizky-kur/Redux-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Insert.java
26 lines (26 loc) · 968 Bytes
/
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
import java.util.Scanner;;
public class Insert{
public static void Insertion_sort(int []A){
for(int j=1;j<A.length;j++)
{ int key=A[j];
int i=j-1;
while(i>=0 && A[i]>key){
A[i+1]=A[i];
i=i-1;}
A[i+1]=key;}}
public static void main(String[] args) {
long start_time = System.currentTimeMillis();
Scanner sc=new Scanner(System.in);
System.out.print("Enter how many Elements:");
int n=sc.nextInt();
int[]A=new int[n];
System.out.println("Enter Digits");
for(int i=0;i<A.length;i++)
A[i]=sc.nextInt();
Insertion_sort(A);
for(int i=0;i<A.length;i++)
System.out.print(A[i]+"\t");
System.out.println(" ");
long end_time = System.currentTimeMillis();
long difference = end_time-start_time;
System.out.println("total time taken = " +difference);}}