Created
December 17, 2014 03:59
-
-
Save hrdavis/17ccc42ad75f5255485c to your computer and use it in GitHub Desktop.
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
package insertion.sort; | |
public class InsertionSort | |
{ | |
public static void Insertion_Sort( Integer[] A ) | |
{ | |
int key; | |
int i; | |
for ( int j = 2; j < A.length; j++ ) | |
{ | |
key = A[ j ]; | |
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 ) | |
{ | |
Integer[] A = { null, 3, 2, 6, 5, 1, 4, 8, 9, 7 }; | |
Insertion_Sort( A ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment