Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Shellsort
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Pseudocode == Using Marcin Ciura's gap sequence, with an inner insertion sort. <syntaxhighlight lang="c"> # Sort an array a[0...n-1]. gaps = [701, 301, 132, 57, 23, 10, 4, 1] # Ciura gap sequence # Start with the largest gap and work down to a gap of 1 # similar to insertion sort but instead of 1, gap is being used in each step foreach (gap in gaps) { # Do a gapped insertion sort for every element in gaps # Each loop leaves a[0..gap-1] in gapped order for (i = gap; i < n; i += 1) { # save a[i] in temp and make a hole at position i temp = a[i] # shift earlier gap-sorted elements up until the correct location for a[i] is found for (j = i; (j >= gap) && (a[j - gap] > temp); j -= gap) { a[j] = a[j - gap] } # put temp (the original a[i]) in its correct location a[j] = temp } } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)