finish 01-homework

This commit is contained in:
SJ2050
2021-10-16 23:35:28 +08:00
parent 1a2d27dc09
commit 001839394c
12 changed files with 369 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
'''
Author: SJ2050
Date: 2021-10-16 21:05:23
LastEditTime: 2021-10-16 23:25:39
Version: v0.0.1
Description: Solution for homework6.
Copyright © 2021 SJ2050
'''
def quickSort(lists, i, j):
if i >= j:
return list
pivot = lists[i]
low = i
high = j
while i < j:
while i < j and lists[j] <= pivot:
j -= 1
lists[i]=lists[j]
while i < j and lists[i] >= pivot:
i += 1
lists[j]=lists[i]
lists[j] = pivot
quickSort(lists,low,i-1)
quickSort(lists,i+1,high)
return lists
if __name__ == '__main__':
# 采用快速排序法进行列表排序
lists = [1, 10, 4, 2, 9, 2, 34, 5, 9, 8, 5, 0]
ordered_lists = quickSort(lists, 0, len(lists)-1)
print('从大到小排列后的列表为: ')
print(ordered_lists)