快速排序
一、大概思路
第一趟排序过程
二、代码实现
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 14 15:27:01 2021
@author: lenovo
快速排序算法实现
"""
def partition(array,i,j):
temp = array[i]
while i != j:
while j > i and array[j] >= temp:
j -= 1
array[i] = array[j]
while i < j and array[i] <= temp:
i+=1
array[j] = array[i]
array[i] = temp
return i
def quick_sort(array,s,t):
i = 0
if s < t:
i = partition(array,s,t)
quick_sort(array,s,i-1)
quick_sort(array,i+1,t)
return array
array = [32,15,11,26,53,87,3,61]
print(array)
print(quick_sort(array,0,7))
2.打印结果
下一篇
分治法之二路归并排序