from randomimport Random
def quick_sort(arry):
if len(arry) >1:
qsort(arry, 0, len(arry) -1)
def qsort(arry, start, end):
base = arry[start]
l = start
r = end
while l < r:
while l < rand arry[r] >= base:
r -=1
if l == r:
break
else:
arry[l], arry[r] = arry[r], arry[l]
while l < rand arry[l] <= base:
l +=1
if l == r:
break
else:
arry[l], arry[r] = arry[r], arry[l]
# now l == r
if l -1 > start:
qsort(arry, start, l -1)
if r +1 < end:
qsort(arry, r +1, end)
r = Random()
a = []
for iin range(10):
a.append(r.randint(0, 100))
print(a)
quick_sort(a)
print(a)
网友评论