Skip to content

Instantly share code, notes, and snippets.

@AntiKnot
Created April 2, 2020 05:48
Show Gist options
  • Select an option

  • Save AntiKnot/bab33bfc321de5b8c3ddd97c9875b4ea to your computer and use it in GitHub Desktop.

Select an option

Save AntiKnot/bab33bfc321de5b8c3ddd97c9875b4ea to your computer and use it in GitHub Desktop.
鸡尾酒排序
test_case = [2, 4, 6, 8, 0]
def wine_sort(l):
if l is []:
return []
length = len(l)
left = 0
right = length
while left < right:
for i in range(left, right):
if l[i] > l[i + 1]:
tmp = l[i + 1]
l[i + 1] = l[i]
l[i] = tmp
right -= 1
for j in range(right, left)[::-1]:
if l[j] < l[j - 1]:
tmp = l[j - 1]
l[j - 1] = l[j]
l[j] = tmp
left -= 1
return l
if __name__ == '__main__':
res = wine_sort(test_case)
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment