mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
Adding unit tests for sorting functions, and improving readability on some sorting algorithms (#784)
* Adding variable to fade out ambiguity * More readability on merge sorting algorithm * Updating merge_sort_fastest description and explaining why * Adding tests file with imports * Standardazing filenames and function names * Adding test cases and test functions * Adding test loop * Putting 'user oriented code' inside main condition for having valid imports * Fixing condition * Updating tests: adding cases and todo list * Refactoring first euler problem's first solution
This commit is contained in:
@ -29,10 +29,12 @@ def insertion_sort(collection):
|
||||
>>> insertion_sort([-2, -5, -45])
|
||||
[-45, -5, -2]
|
||||
"""
|
||||
for index in range(1, len(collection)):
|
||||
while index > 0 and collection[index - 1] > collection[index]:
|
||||
collection[index], collection[index - 1] = collection[index - 1], collection[index]
|
||||
index -= 1
|
||||
|
||||
for loop_index in range(1, len(collection)):
|
||||
insertion_index = loop_index
|
||||
while insertion_index > 0 and collection[insertion_index - 1] > collection[insertion_index]:
|
||||
collection[insertion_index], collection[insertion_index - 1] = collection[insertion_index - 1], collection[insertion_index]
|
||||
insertion_index -= 1
|
||||
|
||||
return collection
|
||||
|
||||
|
Reference in New Issue
Block a user