Skip to content

Instantly share code, notes, and snippets.

@metallurgix
Created July 9, 2014 18:05
Show Gist options
  • Save metallurgix/73908ccd0992eec368f3 to your computer and use it in GitHub Desktop.
Save metallurgix/73908ccd0992eec368f3 to your computer and use it in GitHub Desktop.
Insertion Sort
public class InsertionSort
{
private static int[] a;
private static int n;
public static void sort(int[] b)
{
a=b;
n=a.length;
isort();
}
private static void isort()
{
int i, j, t;
for (i=1; i<n; i++)
{
j=i;
t=a[j];
while (j>0 && a[j-1]>t)
{
a[j]=a[j-1];
j--;
}
a[j]=t;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment