返回顶部

收藏

插入排序

更多

伪码请见 Discrete Mathmatics and Its Application. Kenneth Rosen. P174.

#-*- coding: utf-8 -*-

# the insertation sort
# 2012-07-29 noon

a = [3, 2, 4, 1, 5, 4, 2, 3, 6, 5, 7, 4, 1, 0]

for j in range(1, len(a)):
    i = 0
    while a[j] > a[i]:
        i = i + 1
    m = a[j]
    for k in range(j-i):
        a[j-k] = a[j-k-1]
    a[i] = m

print a
#该片段来自于http://outofmemory.cn

标签:python,算法

收藏

0人收藏

支持

0

反对

0