Merge pull request #413 from coregameHD/master

minor improvement (readability) in Insertion Sort
This commit is contained in:
Harshil 2018-10-04 10:16:57 +02:00 committed by GitHub
commit f98a5f7f47
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