minor improvement (readability) in Insertion Sort

This commit is contained in:
Coregame 2018-10-04 13:36:16 +07:00 committed by GitHub
parent e09bf504a0
commit 25c0bd3fbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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