summaryrefslogtreecommitdiff
path: root/progs/a515.py
diff options
context:
space:
mode:
Diffstat (limited to 'progs/a515.py')
-rw-r--r--progs/a515.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/progs/a515.py b/progs/a515.py
new file mode 100644
index 0000000..b57466d
--- /dev/null
+++ b/progs/a515.py
@@ -0,0 +1,22 @@
+def merge(a,b):
+ c = []
+ while len(a) != 0 and len(b) != 0:
+ if a[0] < b[0]:
+ c.append(a[0])
+ a.remove(a[0])
+ else:
+ c.append(b[0])
+ b.remove(b[0])
+ if len(a) == 0:
+ c += b
+ else:
+ c += a
+ return c
+def merge_sort(x):
+ if len(x) == 0 or len(x) == 1:
+ return x
+ else:
+ middle = len(x)//2
+ a = merge_sort(x[:middle])
+ b = merge_sort(x[middle:])
+ return merge(a,b)