mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
minor improvement (readability) in Insertion Sort
This commit is contained in:
parent
e09bf504a0
commit
25c0bd3fbb
@ -30,9 +30,8 @@ def insertion_sort(collection):
|
||||
[-45, -5, -2]
|
||||
"""
|
||||
for index in range(1, len(collection)):
|
||||
while 0 < index and collection[index] < collection[index - 1]:
|
||||
collection[index], collection[
|
||||
index - 1] = collection[index - 1], collection[index]
|
||||
while index > 0 and collection[index - 1] > collection[index]:
|
||||
collection[index], collection[index - 1] = collection[index - 1], collection[index]
|
||||
index -= 1
|
||||
|
||||
return collection
|
||||
|
Loading…
Reference in New Issue
Block a user