#!/usr/bin/python
'''file name: insertion_sort.py
--P18
--insertion sort
--author: zevolo, 2012.04.28
--modify on 06.07 for stable issue
'''
def insert(list):
for i in range(1, len(list)):
x = list[i]
for j in range(i-1, -1, -1):
if list[j] > x:
list[j+1] = list[j]
else:
list[j+1] = x
break
if __name__ == '__main__':
list = [1, 9, 28, 2, 3, 4, 8]
print "before sort:"
print list
insert(list)
print "after sort:"
print list