• 效率较高的排序算法


    1.快排

    思路:选取一个值,将比他小的放在他左边,比他大的放在他右边

    #!usr/bin/env python
    # -*- coding:utf-8 -*-
    import random
    def quick_sort(data,left,right):
    if left < right:
    mid = partition(data,left,right)
    quick_sort(data,left,mid-1)
    quick_sort(data,mid+1,right)

    def partition(data,left,right):
    tmp = data[left]
    while left < right:
    while left < right and data[right] >= tmp:
    right -= 1
    data[left] = data[right]
    while left < right and data[left] <= tmp:
    left += 1
    data[right] = data[left]
    data[left] = tmp
    return left

    data = list(range(10000))
    random.shuffle(data)#打乱数据
    print(data)
    quick_sort(data,0,len(data)-1)
    print(data)



  • 相关阅读:
    NOI2018 退役记
    APIO2018 被屠记
    CTSC2018 被屠记
    SNOI2018 退役记
    O(1) long long a*b%p
    prufer编码
    杜教筛
    GCC卡常
    NOIP2017滚粗记
    UVA 10763 Foreign Exchange
  • 原文地址:https://www.cnblogs.com/cansun/p/8689183.html
Copyright © 2020-2023  润新知