Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 5, 2014 23:51
Show Gist options
  • Save globby/9379256 to your computer and use it in GitHub Desktop.
Save globby/9379256 to your computer and use it in GitHub Desktop.
An implementation of the Cocktail Sort algorithm
def Cocktail(lst):
swapped = True
while swapped:
swapped = False
for i in range(0,len(lst)-2):
if lst[i] > lst[i+1]:
lst[i], lst[i+1] = lst[i+1], lst[i]
swapped = True
if not swapped:
break
for i in range(len(lst)-2,0,-1):
if lst[i] > lst[i+1]:
lst[i], lst[i+1] = lst[i+1], lst[i]
swapped = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment