aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/algorithms/impl/merge_sort.py
diff options
context:
space:
mode:
Diffstat (limited to 'algorithms/impl/merge_sort.py')
-rw-r--r--algorithms/impl/merge_sort.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/algorithms/impl/merge_sort.py b/algorithms/impl/merge_sort.py
index 9fa96ec..8d0b573 100644
--- a/algorithms/impl/merge_sort.py
+++ b/algorithms/impl/merge_sort.py
@@ -2,6 +2,10 @@
# This file is licensed under the terms of the MIT License.
# See LICENSE.txt for details.
+import sys
+
+from ..algorithm import SortingAlgorithm
+
def merge(left, right):
result = []
l, r = 0, 0
@@ -24,11 +28,16 @@ def merge_sort(xs):
mid = len(xs) // 2
return merge(merge_sort(xs[:mid]), merge_sort(xs[mid:]))
+_ALGORITHMS = [
+ SortingAlgorithm('merge_sort', 'Merge sort', merge_sort),
+]
+
+def _parse_args(args=sys.argv):
+ return list(map(int, args[1:]))
+
+def main(args=sys.argv):
+ xs = _parse_args(args)
+ print(merge_sort(list(xs)))
+
if __name__ == '__main__':
- import sys
- print(merge_sort(list(map(int, sys.argv[1:]))))
-else:
- from algorithms.algorithm import SortingAlgorithm
- _ALGORITHMS = [
- SortingAlgorithm('merge_sort', 'Merge sort', merge_sort),
- ]
+ main()