2025年5月15日 星期四

selection sort recursive edition

 d = [6,7,8,9,1,2,3,4,5]


def selsort(d):

  if len(d)==0:return []

  minV = min(d)

  d.remove(minV)

  return [minV] + selsort(d)

print(selsort(d))


# Output:


# [1, 2, 3, 4, 5, 6, 7, 8, 9]

沒有留言:

張貼留言