欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

快速排序算法Python实现教程

程序员文章站 2022-06-26 09:00:54
def sub_sort(arr,low,high): key=arr[low] while lowwhile lowand arr[high]>=k...
def sub_sort(arr,low,high):
    key=arr[low]
    while lowwhile lowand arr[high]>=key:
            high-=1
        arr[low]=arr[high]
        while lowand arr[low]<=key:
            low+=1
        arr[high]=arr[low]
    arr[low]=key
    return low

def quick_sort(arr,low,high):
    if lowif __name__=='__main__':
    arr=[8,7,6,0,8,9,12,45,78,23,45,67]
    print(arr)
    quick_sort(arr, 0, len(arr)-1)
    print(arr)