Skip to content

Commit f98a5f7

Browse files
authored
Merge pull request TheAlgorithms#413 from coregameHD/master
minor improvement (readability) in Insertion Sort
2 parents e09bf50 + 25c0bd3 commit f98a5f7

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

sorts/insertion_sort.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ def insertion_sort(collection):
3030
[-45, -5, -2]
3131
"""
3232
for index in range(1, len(collection)):
33-
while 0 < index and collection[index] < collection[index - 1]:
34-
collection[index], collection[
35-
index - 1] = collection[index - 1], collection[index]
33+
while index > 0 and collection[index - 1] > collection[index]:
34+
collection[index], collection[index - 1] = collection[index - 1], collection[index]
3635
index -= 1
3736

3837
return collection

0 commit comments

Comments
 (0)