Commit 5d4ecf62 by 安晓东

第四次作业算法题

parent 3ee68a34
def convert(s, numRows):
if numRows == 1 and numRows >= len(s):
return s
li = [[] for x in range(numRows)]
row, step = 0, 1
for i in s:
li[row].append(i)
if row == 0:
step = 1
elif row == numRows - 1:
step = -1
row += step
result = ''
for y in range(len(li)-1):
result = result+''.join(li[y])
return result
s = convert("PAYPALISHIRING", 4)
print(s)
def quick_sort(sort_list, start_index, end_index):
if start_index < end_index: # 如果角标左侧小于右侧则开始排序,否则退出
basic, i, j = sort_list[start_index], start_index, end_index
while i < j:
while i < j and basic <= sort_list[j]: # 基准值比j(右侧)小,那么该值不做任何事情
j -= 1
while i < j and basic >= sort_list[i]:
i += 1
sort_list[i], sort_list[j] = sort_list[j], sort_list[i]
sort_list[i], sort_list[start_index] = sort_list[start_index], sort_list[i]
quick_sort(sort_list, start_index, i - 1)
quick_sort(sort_list, i + 1, end_index)
l = [10, 6, 9, 18, 20, 5, 7, 15, 14, 18,19]
quick_sort(l,0,len(l)-1)
print(l)
\ 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