Created
March 6, 2014 00:04
-
-
Save globby/9379410 to your computer and use it in GitHub Desktop.
An implementation of the Gnomesort algorithm
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
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