insertion_sort.py 插入排序

动态图:https://visualgo.net/zh/sorting

python语句:

#coding: utf-8
# 插入排序
input = raw_input("input several numbers: ")
numbers = map(int,input.split(' '))

n = len(numbers)

for j in range(n-1):
	for i in range(j+1,0,-1):
		if numbers[i] < numbers[i-1]:
			numbers[i],numbers[i-1] = numbers[i-1],numbers[i]

print numbers

你可能感兴趣的:(algorithm,in,python)