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:
Du Yuanchao
2020-09-10 16:31:26 +08:00
committed by GitHub
parent 25946e4570
commit 4d0a8f2355
60 changed files with 900 additions and 859 deletions

View File

@ -16,14 +16,14 @@ def printMaxActivities(start, finish):
>>> finish = [2, 4, 6, 7, 9, 9]
>>> printMaxActivities(start, finish)
The following activities are selected:
0 1 3 4
0,1,3,4,
"""
n = len(finish)
print("The following activities are selected:")
# The first activity is always selected
i = 0
print(i, end=" ")
print(i, end=",")
# Consider rest of the activities
for j in range(n):
@ -32,16 +32,15 @@ def printMaxActivities(start, finish):
# or equal to the finish time of previously
# selected activity, then select it
if start[j] >= finish[i]:
print(j, end=" ")
print(j, end=",")
i = j
# Driver program to test above function
start = [1, 3, 0, 5, 8, 5]
finish = [2, 4, 6, 7, 9, 9]
printMaxActivities(start, finish)
if __name__ == "__main__":
import doctest
"""
The following activities are selected:
0 1 3 4
"""
doctest.testmod()
start = [1, 3, 0, 5, 8, 5]
finish = [2, 4, 6, 7, 9, 9]
printMaxActivities(start, finish)