字符串冒泡排序方法

def str_bubble(s1):
    if s1:
        if isinstance(s1[0], int):
            n = len(s1)
            s1 = list(map(lambda x: str(x), s1))
        else:
            pass
        for i in range(n):
            for j in range(i + 1, n):
                if int(s1[i] + s1[j]) > int(s1[j] + s1[i]):
                    pass
                else:
                    s1[i], s1[j] = s1[j], s1[i]
    return s1

 

posted @ 2022-07-02 12:08  pie神  阅读(77)  评论(0编辑  收藏  举报