Python算法之插入排序
初学Python,写一些算法作为练手。输入‘e' 作为输入的结束
Python算法之插入排序代码:
def insert_sort(seq):
length = len(seq)
for i in range(1,length):
temp = seq[i]
for j in range(i-1, -1, -1):
if temp < seq[j]:
seq[j+1]=seq[j]
else:
j+=1
break
if seq[j] is not temp:
seq[j]=temp
def do_test():
seq = []
print('Please input the sequence:')
while True:
ch = input()
if ch is 'e':
break
seq.append(int(ch))
insert_sort(seq)
print('After the insertSort:')
print(seq)
if __name__ == '__main__':
do_test()
推荐阅读:
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16