diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-04-17 00:49:33 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-04-17 00:49:33 +0300 |
commit | 2183f3f860af34e45058ef078045322062b51f42 (patch) | |
tree | 1f61c51be301db314720fe4a945d6ddaaffa8249 /merge_sort.py | |
parent | README update (diff) | |
download | sorting-algorithms-2183f3f860af34e45058ef078045322062b51f42.tar.gz sorting-algorithms-2183f3f860af34e45058ef078045322062b51f42.zip |
rearrange source files
* Add a useful `algorithms` package to provide convinient access to the
implemented algorithms.
* This allows to e.g. dynamically list available algorithms, which
greatly simplifies a lot of things.
Diffstat (limited to 'merge_sort.py')
-rw-r--r-- | merge_sort.py | 29 |
1 files changed, 0 insertions, 29 deletions
diff --git a/merge_sort.py b/merge_sort.py deleted file mode 100644 index 6d5403d..0000000 --- a/merge_sort.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2015 Egor Tensin <Egor.Tensin@gmail.com> -# This file is licensed under the terms of the MIT License. -# See LICENSE.txt for details. - -def merge(left, right): - result = [] - l, r = 0, 0 - while l < len(left) and r < len(right): - if left[l] <= right[r]: - result.append(left[l]) - l += 1 - else: - result.append(right[r]) - r += 1 - if left: - result.extend(left[l:]) - if right: - result.extend(right[r:]) - return result - -def merge_sort(xs): - if len(xs) < 2: - return xs - mid = len(xs) // 2 - return merge(merge_sort(xs[:mid]), merge_sort(xs[mid:])) - -if __name__ == '__main__': - import sys - print(merge_sort(list(map(int, sys.argv[1:])))) |