美文网首页
快速排序装饰器算时间

快速排序装饰器算时间

作者: 铁甲依然在人间 | 来源:发表于2021-09-06 14:53 被阅读0次
    import time
    
    
    
    def runtime(func):
        def wrapper(*args,**kwargs):
            start=time.perf_counter()
            func(*args,**kwargs)
            end =time.perf_counter()
            print(end -start)
        return wrapper
    # @runtime
    # def quick (L):
    #     m=L[1]
    #     L.remove(m)
    #     right ,left= [],[]
    #     for x in L:
    #         if x>m:
    #             right.append(x)
    #         else:
    #             left.append(x)
    #     return left+[m]+right
    def quick (L):
        if len(L) ==0:
            return []
        m=L[len(L)//2]
        L.remove(m)
        left =quick([x for x in L if x <m])
        right =quick([x for x in L if x >m])
        return left+[m]+right
    
    
    
    
    quick([10, 17, 50, 7, 30, 24, 27, 45, 15, 5, 36, 21])
    

    相关文章

      网友评论

          本文标题:快速排序装饰器算时间

          本文链接:https://www.haomeiwen.com/subject/vjgewltx.html