使用插入排序实现排序(废话)

python

def insertSort(list):
    for i in range(1,len(list)):
        j = i-1
        temp = list[i]
        while (j>=0) & (temp < list[j]):
           list[j+1] = list[j]
           j = j-1
        list[j+1]=temp
    return list


list = [6,2,7,4,3]
print insertSort(list)
#[2, 3, 4, 6, 7]

 

相关文章:

  • 2021-11-27
  • 2022-01-17
  • 2021-04-09
  • 2021-08-13
猜你喜欢
  • 2022-02-22
  • 2021-09-24
  • 2022-02-24
  • 2021-06-14
  • 2021-11-05
  • 2021-10-12
相关资源
相似解决方案