用Python写插入排序
程序员文章站
2022-03-08 16:56:11
...
#插入排序 #定义一个数组 a = [34, 8, 64, 51, 32, 21] #插入排序算法实现 for i in range(1, len(a)): print a print 'i is ', i tmp = a[i] print 'tmp is ', tmp b = range(1, i + 1) b.reverse() for c in b: print 'c is ', c, 'a[c] is ', a[c], 'a[c - 1] is ', a[c-1] if a[c] < a[c-1]: a[c] = a[c - 1] a[c-1] = tmp
上一篇: 如何用 Python 爬取网页制作电子书