aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/algorithms/impl/bubble_sort.py
diff options
context:
space:
mode:
Diffstat (limited to 'algorithms/impl/bubble_sort.py')
-rw-r--r--algorithms/impl/bubble_sort.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/algorithms/impl/bubble_sort.py b/algorithms/impl/bubble_sort.py
index 95fb661..0ea66bb 100644
--- a/algorithms/impl/bubble_sort.py
+++ b/algorithms/impl/bubble_sort.py
@@ -7,6 +7,7 @@ import sys
from ..algorithm import SortingAlgorithm
+
def bubble_sort(xs):
while True:
swapped = False
@@ -18,6 +19,7 @@ def bubble_sort(xs):
break
return xs
+
def bubble_sort_optimized(xs):
n = len(xs)
while True:
@@ -31,20 +33,24 @@ def bubble_sort_optimized(xs):
break
return xs
+
_ALGORITHMS = [
SortingAlgorithm('bubble_sort', 'Bubble sort', bubble_sort),
SortingAlgorithm('bubble_sort_optimized', 'Bubble sort (optimized)', bubble_sort_optimized),
]
+
def _parse_args(args=None):
if args is None:
args = sys.argv[1:]
return list(map(int, args))
+
def main(args=None):
xs = _parse_args(args)
print(bubble_sort(list(xs)))
print(bubble_sort_optimized(list(xs)))
+
if __name__ == '__main__':
main()