Skip to content

Instantly share code, notes, and snippets.

@codelance
Created December 2, 2012 01:22
Show Gist options
  • Select an option

  • Save codelance/4186387 to your computer and use it in GitHub Desktop.

Select an option

Save codelance/4186387 to your computer and use it in GitHub Desktop.
Straight Insertion Sort
public class StraightInsertionSort {
/*insertionsort
Description: Performs a insertion sort on a given list
Parameters:
int[] list: array of integers to be sorted
Pre: Initialized array
Post: Sorted array
Returns: Sorted array
Called by: Any
Calls: None
*/
public static int[] insertionsort(int[] list)
{
int i, k, y;
for( k = 1; k < list.length; k++)
{
y = list[k];
for( i = k-1; i >= 0 && y < list[i]; i--)
{
list[i+1] = list[i];
}
list[i+1] = y;
}
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment