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
Comb sort
(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=== '''function''' combsort('''array''' input) '''is''' gap := input.size <span style="color:green">// Initialize gap size</span> shrink := 1.3 <span style="color:green">// Set the gap shrink factor</span> sorted := false '''loop while''' sorted = false <span style="color:green">// Update the gap value for a next comb</span> gap := floor(gap / shrink) '''if''' gap β€ 1 '''then''' gap := 1 sorted := true <span style="color:green">// If there are no swaps this pass, we are done</span> '''else if''' gap = 9 '''or''' gap = 10 '''then''' gap := 11 <span style="color:green">// The "rule of 11"</span> '''end if''' <span style="color:green">// A single "comb" over the input list</span> i := 0 '''loop while''' i + gap < input.size<span style="color:green"> // See [[Shell sort]] for a similar idea</span> '''if''' input[i] > input[i+gap] '''then''' [[Swap (computer science)|swap]](input[i], input[i+gap]) sorted := false <span style="color:green">// If this assignment never happens within the loop, // then there have been no swaps and the list is sorted.</span> '''end if''' i := i + 1 '''end loop''' '''end loop''' '''end function''' <!-- Please do not modify the pseudocode to make corrections unless you have verified, by translating the pseudocode to an actual programming language, that the corrections actually *are* corrections. Especially don't try to optimize it at the expense of clarity or understandability. -->
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)