2025年5月9日 星期五

insert sort python edition

 d = list(range(110,100,-1))+list(range(1,11))

print(d)

t = d[0:]


for i in t:

  d = [j for j in d if j<i] + [i] + [j for j in d if j>i]

print(d)


Output:


[110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]

沒有留言:

張貼留言