m0_64221420
2021-12-10 23:21
采纳率: 100%
浏览 111
已结题

关于#python#的问题:python编写函数myfunc(),模拟内置函数sorted()功能

python编写函数myfunc(),模拟内置函数sorted()功能。注:程序中不允许出现sorted()函数
运行结果:

img

图片转代码服务由CSDN问答提供 功能建议

Theoriginallistis:[82,74,99,95,66,11,83,9,63,44,46,53,97,56,
81, 16,43,8,32,79,100,51,66,55,38,70,89,57,10,20,9,28,69,53,
50, 64, 86,20,50,9,47,29,11,86,97,46,82,61,15,56,88,68,97,40,
59 73,28,78,76,72,88,100,19,2,87,8,2,10,55,65,99,13,36,68,
        10, 31 38,5,77,70,18,5,44,12,57,98,22,47,30,41,40,55,37,70,
39, 19,75,85,35,30]
The sortedlistis:[2,2,5,5,8,8,9,9,9,10,10,10,11,11,12,13,15,
        18,19,19, 31,32,35, 38 16, 20,22, 28, 28, 29, 30, 36,37, 20,2 30, 38
                        41, 46,46,47,47,50,50,51,53,53,55,55, 40, 44,44,4 39 40, 43 55
                                59 61,63,64, 56. 56 57. 57 65. 68,69, 70, 70, 66, 66, 68, 70, 72, 73,
                                78
74 75 76 77 82, 85, 86,87,8 88, 82, 83, 86, 88, 95 79, 89, 81. 97,
                                99
        97, 99, 97 98, 100, 100]
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • bekote 2021-12-11 00:10
    最佳回答
    
    def myfunc(a):
        for i in range(len(a)):
            for j in range(i+1, len(a)):
                if a[j] < a[i]:
                    tmp = a[i]
                    a[i] = a[j]
                    a[j] = tmp
    
    评论
    解决 1 无用
    打赏 举报

相关推荐 更多相似问题