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]

-----------------------------------------------
展开阅读全文

没有更多推荐了,返回首页