mergesort in python

def mergesort(List):
    """ input : List, an integer list
        output : an sorted integer list
    """
    n = len(List)
    if n == 0 or n==1:
        return List
    first = mergesort(List[:n/2])
    second =  mergesort(List[n/2:])
    i=0
    j=0
    output = []
    while True:
        if first[i]<second[j]:
            output.append(first[i])
            i += 1
        else:
            output.append(second[j])
            j += 1
        if i >= len(first):
            output += second[j:]
                
            break
        if j >= len(second):
            output += first[i:]
                
            break
        
    return output

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
那一天的Java_J...:他本来公司就是做这个的,不就是正常的游戏客户端和服务器开发,软硬件联动,有啥恶心不恶心的,提前告诉你就是怕你接受不了,接受不了就没必要再往后走流程浪费时间,虽然这公司是一坨。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务