码迷,mamicode.com
首页 > 编程语言 > 详细

python快速排序

时间:2019-09-22 23:25:06      阅读:112      评论:0      收藏:0      [点我收藏+]

标签: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 < right and arr[right] >= pivotkey:
            right -= 1
        arr[left] = arr[right]
        while left < right 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!