代码:
1 def partition(data,left,right): 2 tmp = data[left] 3 while left<right: 4 while left < right and data[right]>=tmp: 5 right -=1 6 data[left] = data[right] 7 while left < right and data[left]<=tmp: 8 left +=1 9 data[right] = data[left] 10 data[left]=tmp 11 return left 12 13 def quick_sort(data,left,right): 14 if (left >= right): 15 return 16 mid = partition(data,left,right) 17 quick_sort(data,left,mid-1) 18 quick_sort(data,mid+1,right) 19 def test(): 20 data = [23,88,44,11,90,48,33,89] 21 quick_sort(data,0,7) 22 for i in data: 23 print(i) 24 test()
其实各种算法对各个编程语言而言都是相通的,除了语法上的不同之外灵魂都是一样的。其他的排序算法可以查看java下的实现。