aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/algorithms/impl/bubble_sort.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2019-12-23 07:32:18 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2019-12-23 07:32:18 +0300
commit0d25b5d6957d76bab486e2279c99e130c19d5c31 (patch)
treec8c7d6fe4766470bda03e49a004afaa03c967b16 /algorithms/impl/bubble_sort.py
parentTravis: add badge to README (diff)
downloadsorting-algorithms-0d25b5d6957d76bab486e2279c99e130c19d5c31.tar.gz
sorting-algorithms-0d25b5d6957d76bab486e2279c99e130c19d5c31.zip
pylint/pep8 fixes
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()