快排过程比较简单就直接上代码了:
1 #!/usr/bin/python3 2 3 def quik_sort(L, left, right): 4 if left <= right: 5 key = L[left] 6 i = left 7 j = right 8 while i < j: 9 while i < j and key <= L[j]: 10 j -= 1 11 L[i] = L[j] 12 while i < j and L[i] <= key: 13 i += 1 14 L[j] = L[i] 15 L[i] = key 16 quik_sort(L, left, i - 1) 17 quik_sort(L, i + 1, right) 18 19 20 21 a = list(map(int, input().split())) 22 23 quik_sort(a, 0, len(a) - 1) 24 25 for x in a: 26 print(x, end = ‘ ‘) 27 print()
注意:python 中的数字类型是不可变的,因此 x++ 并不会让 x 的值加 1
原文地址:https://www.cnblogs.com/geloutingyu/p/8747440.html
时间: 2024-10-14 04:11:48