Created
April 2, 2020 05:48
-
-
Save AntiKnot/bab33bfc321de5b8c3ddd97c9875b4ea to your computer and use it in GitHub Desktop.
鸡尾酒排序
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
| 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