Created
July 9, 2014 18:05
-
-
Save metallurgix/73908ccd0992eec368f3 to your computer and use it in GitHub Desktop.
Insertion Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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