Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 6, 2014 00:00
Show Gist options
  • Save globby/9379375 to your computer and use it in GitHub Desktop.
Save globby/9379375 to your computer and use it in GitHub Desktop.
An implementation of the Combsort algorithm
def combsort(lst):
gap = len(lst)
shrink = 1.3
swapped = True
while not (gap == 1 and not swapped):
gap = int(gap/shrink)
if gap < 1:
gap = 1
i = 0
swapped = False
while not i + gap >= len(lst):
if lst[i] > lst[i+gap]:
lst[i], lst[i+gap] = lst[i+gap], lst[i]
swapped = True
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment