【python】快速排序
快速排序思想和C++的差不多,主要是通过写排序对python的语法更加了解。
# 快速排序 def qsort(arr, left, right): if left >= right: return arr x = arr[left] l = left r = right while left < right: while left < right and arr[right] >= x: right -= 1 arr[left] = arr[right] while left < right and arr[left] <= x: left += 1 arr[right] = arr[left] arr[right] = x qsort(arr, l, left - 1) qsort(arr, left + 1, r) return arr print(qsort([9,2,6,7,4,0],0,5))