码迷,mamicode.com
首页 > 编程语言 > 详细

python实现插入排序

时间:2015-05-24 21:32:35      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

#_*_coding:utf-8-*-

def Insert(x,n):
    i = 1;
    while i<=n-1:
        key = x[i]
        j = i-1
        while j >= 0 and key<x[j]:
            x[j+1] = x[j]
            j -= 1
        x[j+1] = key
        i+=1
    return x
list_test = [12,32,54,63,89,4,3,52,631,14,25]
print("插入排序之前的数据:%s" %list_test)

print("插入排序之后的数据:%s" %Insert(list_test,len(list_test)))

 

python实现插入排序

标签:

原文地址:http://www.cnblogs.com/blogofwyl/p/4526367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!