python实现插入排序

时间:2021-07-25 06:23:49

代码如下@.·.@

# *-*   coding: utf-   *-*

if __name__ == '__main__':
def insert_sort(l):
for i in xrange(,len(l)):
tmp = l[i]
key = i-
while (key >= and tmp < l[key]):
l[key+] = l[key]
key-= if ((key+) != i):
# l.insert(key,tmp)
# else:
# m.insert(key+,tmp)
l[key+] = tmp
return l print insert_sort([,,,,,,,,])