Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 6, 2014 00:04
Show Gist options
  • Save globby/9379410 to your computer and use it in GitHub Desktop.
Save globby/9379410 to your computer and use it in GitHub Desktop.
An implementation of the Gnomesort algorithm
def gnomesort(lst):
pos = 1
while pos < len(lst):
if lst[pos] >= lst[pos-1]:
pos += 1
else:
lst[pos], lst[pos-1] = lst[pos-1], lst[pos]
if pos > 1:
pos -= 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment