A recursive function to sort a list of ints

后端 未结 4 665
一整个雨季
一整个雨季 2021-01-29 14:09

I want to define a recursive function can sort any list of ints:

def sort_l(l):
    if l==[]:
        return []
    else:
        if len(l)==1:
            retur         


        
4条回答
  •  心在旅途
    2021-01-29 14:49

    def sort(array, index = 0, bigNumber = 0):
      if len(array) == index:
        return array
    
      elif bigNumber > array[index]:
        array[index - 1] = array[index]
        array[index] = bigNumber
        bigNumber = array[0]
        index = 0
    
      else:
        bigNumber = array[index]
    
      return sort(array, (index + 1), bigNumber)
    

提交回复
热议问题