import time
def runtime(func):
def wrapper(*args,**kwargs):
start=time.perf_counter()
func(*args,**kwargs)
end =time.perf_counter()
print(end -start)
return wrapper
# @runtime
# def quick (L):
# m=L[1]
# L.remove(m)
# right ,left= [],[]
# for x in L:
# if x>m:
# right.append(x)
# else:
# left.append(x)
# return left+[m]+right
def quick (L):
if len(L) ==0:
return []
m=L[len(L)//2]
L.remove(m)
left =quick([x for x in L if x <m])
right =quick([x for x in L if x >m])
return left+[m]+right
quick([10, 17, 50, 7, 30, 24, 27, 45, 15, 5, 36, 21])
网友评论