Skip to content

Instantly share code, notes, and snippets.

@fabian57
Last active August 29, 2015 14:14
Show Gist options
  • Save fabian57/257c797813cd107cc52f to your computer and use it in GitHub Desktop.
Save fabian57/257c797813cd107cc52f to your computer and use it in GitHub Desktop.
def gnome_sort(a):
i = 0
while i < len(a)-1:
if a[i] > a[i+1] and i >= 0:
(a[i], a[i+1]) = (a[i+1], a[i])
i -= 1
else:
i += 1
a = [4, 2, 42, 356, 5, 100, 1]
gnome_sort(a)
a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment