a
= [1,5,3,8,10,2,6,3]
for i
in range(1,len(a
)):
key
= a
[i
]
j
= i
- 1
while j
>= 0 and a
[j
] > key
:
a
[j
+1] = a
[j
]
j
= j
- 1
a
[j
+1] = key
print(a
)
b
= [8,3,5,7,2,9,1]
for i
in range(1,len(b
)):
key
= b
[i
]
j
= i
- 1
while j
>= 0 and b
[j
] < key
:
b
[j
+1] = b
[j
]
j
= j
- 1
b
[j
+1] = key
print(b
)
转载请注明原文地址:https://tech.qufami.com/read-10434.html