Skip to content

Commit

Permalink
Merge pull request #205 from kushal13112001/patch-12
Browse files Browse the repository at this point in the history
Create AdvancedInsertionsort.java
  • Loading branch information
IEEE-IIITSricity committed Oct 6, 2020
2 parents 521fe4f + ac72f1e commit 0bb3d04
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Sorting Algorithms/AdvancedInsertionsort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.*;
class Solution
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
int count=0;
for(int i=1;i<n;i++)
{
int in=i;
int val=a[i];
while(in>0 && a[in-1]>val)
{
a[in]=a[in-1];
in--;
count++;
}
a[in]=val;
}
System.out.println(count);
}
}
}

0 comments on commit 0bb3d04

Please sign in to comment.