Commit 51370c36 by bonnieyan

第五次作业

parent 7542ca53
......@@ -2,15 +2,15 @@ class SortUtils:
def sort(self, f, s):
if f == "bubble":
for i in range(len(s) - 1):
for j in range(len(s) - i -1):
for j in range(len(s) - i - 1):
if s[j] > s[j+1]:
s[j], s[j+1] = s[j+1], s[j]
print(s)
#print(s)
if f == "quick":
SortUtils.__quick_sort(s, 0, len(s)-1)
SortUtils.__quick_sort(self, s, 0, len(s)-1)
def __quick_sort(sort_list, start_index, end_index):
def __quick_sort(self, sort_list, start_index, end_index):
# print(sort_list)
if start_index < end_index: # 如果角标左侧小于右侧则开始排序,否则退出
basic, i, j = sort_list[start_index], start_index, end_index
......@@ -26,10 +26,10 @@ class SortUtils:
print("i=" + str(i) + "&&&" + "j=" + str(j) + "$$$" + "sort_list=" + str(sort_list))
sort_list[i], sort_list[start_index] = sort_list[start_index], sort_list[i]
SortUtils.__quick_sort(sort_list, start_index, i - 1)
SortUtils.__quick_sort(sort_list, i + 1, end_index)
SortUtils.__quick_sort(self, sort_list, start_index, i - 1)
SortUtils.__quick_sort(self, sort_list, i + 1, end_index)
p = SortUtils()
p.sort("bubble", [10, 5, 2, 16, 4, 9, 13, 8])
p.sort("quick", [10, 5, 2, 16, 4, 9, 13, 8])
p.sort("quick", [10, 5, 2, 16, 4, 9, 13, 8])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment