Optimized recursive_bubble_sort (#2410)
* optimized recursive_bubble_sort
* Fixed doctest error due whitespace
* reduce loop times for optimization
* fixup! Format Python code with psf/black push
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@@ -29,11 +29,13 @@ def merge_sort(collection: list) -> list:
|
||||
:param right: right collection
|
||||
:return: merge result
|
||||
"""
|
||||
|
||||
def _merge():
|
||||
while left and right:
|
||||
yield (left if left[0] <= right[0] else right).pop(0)
|
||||
yield from left
|
||||
yield from right
|
||||
|
||||
return list(_merge())
|
||||
|
||||
if len(collection) <= 1:
|
||||
@@ -44,6 +46,7 @@ def merge_sort(collection: list) -> list:
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
user_input = input("Enter numbers separated by a comma:\n").strip()
|
||||
unsorted = [int(item) for item in user_input.split(",")]
|
||||
|
||||
Reference in New Issue
Block a user