#!/usr/bin/env python
# coding=utf-8
'''
roy(火炎神) 2010/10/10
插入排序 照着<<算法技术手册>>上写的
'''
import random,time
_data = []
_newData = []
size = 15
def createData():
for i in range(size):
_data.append(random.randrange(0,size))
def sort(a):
for i in range(size):
insert(a,i,a[i])
def insert(a,index,value):
i = index - 1
while i>=0 and a[i]>value :
a[i+1] = a[i]
i = i-1
a[i+1] = value
def main():
createData()
print _data
sort(_data)
print _data
if __name__ == "__main__":
main()
插入排序 python
最新推荐文章于 2022-04-07 13:12:29 发布