mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 05:21:09 +00:00
Merge pull request #413 from coregameHD/master
minor improvement (readability) in Insertion Sort
This commit is contained in:
commit
f98a5f7f47
|
@ -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