Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save codelance/4186383 to your computer and use it in GitHub Desktop.
Shell Sort
public class ShellSort {
/*shellsort
Description: Performs a shell sort on a given list
Parameters:
int[] list: array of integers to be sorted
int[] increments: array of bucket sizes
Pre: Initialized array
Post: Sorted array
Returns: Sorted array
Called by: Any
Calls: None
*/
public static int[] shellsort(int[] list, int[] increments)
{
int incr, j, k, span, y;
for(incr = 0; incr < increments.length; incr++)
{
span = increments[incr];
for(j = span; j < list.length; j++)
{
y = list[j];
for( k = j-span; k >= 0 && y < list[k]; k-=span)
{
list[k+span] = list[k];
}
list[k+span] = y;
}
}
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment