lazysort.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:lazysort 作者: boramalper 项目源码 文件源码
def lazysort(l: list) -> typing.Iterator:
    # Stage 1
    stack = []
    current_list = iter(l)
    sentinel = object()
    first = next(current_list, sentinel)
    while first is not sentinel:
        sortedish, surplus = dropsort(chain((first,), current_list))
        stack.append(sortedish)
        current_list = surplus
        first = next(current_list, sentinel)

    # Stage 2
    if len(stack) < 2:  # the case where the list `l` is already sorted
        return iter(l)

    cur = merge(stack.pop(), stack.pop())
    while stack:
        cur = merge(cur, stack.pop())

    return cur
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号