python快速排序

2020-12-13 14:50

阅读:638

标签:name   排序   def   and   code   pytho   test   col   +=   

# coding=utf-8


def quick_sort(arr, start, end):
    if start >= end:
        return
    left = start
    right = end
    pivotkey = arr[start]
    while left  right:
        while left and arr[right] >= pivotkey:
            right -= 1
        arr[left] = arr[right]
        while left and arr[left]  pivotkey:
            left += 1
        arr[right] = arr[left]

    arr[left] = pivotkey
    quick_sort(arr, start, left-1)
    quick_sort(arr, right + 1, end)


if __name__ == "__main__":
    test_list = [2, 10, 11, 6, 19, 21]
    quick_sort(test_list, 0, len(test_list)-1)
    print(test_list)

 

python快速排序

标签:name   排序   def   and   code   pytho   test   col   +=   

原文地址:https://www.cnblogs.com/qiaokuahai/p/11569731.html


评论


亲,登录后才可以留言!