quick sort in Python

quick sort

def quick_sort(list_02, first, last):
    if first >= last:
        return
    mid_val = list_02[first]
    low = first
    high = last
    while low < high:
        while low < high and list_02[high] >= mid_val:
            high -= 1
        list_02[low] = list_02[high]
        while low < high and list_02[low] < mid_val:
            low += 1
        list_02[high] = list_02[low]
    list_02[low] = mid_val
    quick_sort(list_02, first, low - 1)
    quick_sort(list_02, low + 1, last)

def main():
    list_01 = [2, 4, 55, 1, 6, 28, 54, 55, 19, 95, 48, 65]
    quick_sort(list_01, 0, len(list_01) - 1)
    print(list_01)

if __name__ == '__main__':
    main()


---------------results of enforcement----------
[1, 2, 4, 6, 19, 28, 48, 54, 55, 55, 65, 95]

-----------------------------------------------
展开阅读全文
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值