
主要代码如下:
程序运行的结果如下:
- l = [0,10,20,30,40,50]
- print( 'The sorted list is:',l)
- n = len(l)
- key = int(input('Input a number:'))
- l.append(key)
- def insert_array(l,key):
- for i in range(n):
- if key<l[i]:
- for j in range(n,i,-1):
- l[j] = l[j-1]
- l[i] = key
- break
- insert_array(l,key)
- print('The sorted list is:',l)
The sorted list is: [0, 10, 20, 30, 40, 50]
Input a number:15
The sorted list is: [0, 10, 15, 20, 30, 40, 50]