Created
December 2, 2012 01:21
-
-
Save codelance/4186383 to your computer and use it in GitHub Desktop.
Shell Sort
This file contains hidden or 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 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