美文网首页
快速排序

快速排序

作者: 仁安天下 | 来源:发表于2019-10-13 01:01 被阅读0次
    a_list = [12,13,4,5,1,10,7]
    a_low = 0
    a_high = 6
    def quick_sort(l,low,high):
        pivotkey = l[low]
        while (low<high):
            while (low<high and l[high]>=pivotkey):
                high-=1
            l[low],l[high] = l[high],l[low]
            while (low<high and l[low]<=pivotkey):
                low+=1
            l[low],l[high] = l[high],l[low]
        print low
        print l
        return low
    
    def q_sort(l,low,high):
        if low<high:
            pivotloc = quick_sort(l,low,high)
            q_sort(l,low,pivotloc-1)
            q_sort(l,pivotloc+1,high)
    q_sort(a_list,a_low,a_high)
    print a_list
    

    相关文章

      网友评论

          本文标题:快速排序

          本文链接:https://www.haomeiwen.com/subject/izfhmctx.html