Skip to content

Instantly share code, notes, and snippets.

@hrdavis
Created December 17, 2014 03:59
Show Gist options
  • Save hrdavis/17ccc42ad75f5255485c to your computer and use it in GitHub Desktop.
Save hrdavis/17ccc42ad75f5255485c to your computer and use it in GitHub Desktop.
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