此练习为巩固学习python基础编程
练习一:
python语言的快速排序:
def sort(arr,start,end):
if start<end :
p = func(arr,start,end)
sort(arr,start,p-1)
sort(arr, p+1, end)
return arr
def func(arr,start,end):
low=start
high=end
key = arr[low]
while low<high :
while low<high and arr[high]>=key:
high=high-1
arr[low]=arr[high]
while low<high and arr[low]<=key:
low=low+1
arr[high]=arr[low]
arr[low]=key
return low
if __name__ == '__main__':
arr = [5,3,2 ,77,3,9]
len = len(arr)
sort(arr,0,len-1)
print(arr)