02_快速排序

def quick_sort(data):

    '''

    快速排序

    :paramdata:

    :return:

    '''

    length_data =len(data)

    if length_data <2:

        return data

    mid = length_data //2

    mid_data = data[mid]

    left,right = [],[]

    data.remove(mid_data)

    for d in data:

        if d < mid_data:

            left.append(d)

        else:

            right.append(d)

    return quick_sort(left)+[mid_data]+quick_sort(right)


array = [2,3,5,7,1,4,6,15,5,2,7,9,10,15,9,17,12]

print(quick_sort(array))

你可能感兴趣的:(02_快速排序)