From 20393d0b1eb8a70929068b36ce2e03180ab2296a Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 5 Mar 2020 11:36:49 -0600 Subject: Rename --- csci4041/MergeSortPy.py | 30 ------------------------------ csci4041/mergeSort_py.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 30 deletions(-) delete mode 100644 csci4041/MergeSortPy.py create mode 100644 csci4041/mergeSort_py.py diff --git a/csci4041/MergeSortPy.py b/csci4041/MergeSortPy.py deleted file mode 100644 index bc9ae7d..0000000 --- a/csci4041/MergeSortPy.py +++ /dev/null @@ -1,30 +0,0 @@ -def head(Q): - return Q[0] -def tail(Q): - return Q[1:] -def mergesort(U): - if U == [] or tail(U) == []: - return U - else: - L = [] - R = [] - while U != [] and tail(U) != []: - L = L+[head(U)] - U = tail(U) - R = R+[head(U)] - U = tail(U) - L = L + U - L = mergesort(L) - R = mergesort(R) - s = [] - while L != [] and R != []: - if head(L) <= head(R): - s = s + [head(L)] - L = tail(L) - else: - s = s + [head(R)] - R = tail(R) - s = s + L + R - return s - -print(mergesort([9,3,7,5,6,4,8,2])) \ No newline at end of file diff --git a/csci4041/mergeSort_py.py b/csci4041/mergeSort_py.py new file mode 100644 index 0000000..bc9ae7d --- /dev/null +++ b/csci4041/mergeSort_py.py @@ -0,0 +1,30 @@ +def head(Q): + return Q[0] +def tail(Q): + return Q[1:] +def mergesort(U): + if U == [] or tail(U) == []: + return U + else: + L = [] + R = [] + while U != [] and tail(U) != []: + L = L+[head(U)] + U = tail(U) + R = R+[head(U)] + U = tail(U) + L = L + U + L = mergesort(L) + R = mergesort(R) + s = [] + while L != [] and R != []: + if head(L) <= head(R): + s = s + [head(L)] + L = tail(L) + else: + s = s + [head(R)] + R = tail(R) + s = s + L + R + return s + +print(mergesort([9,3,7,5,6,4,8,2])) \ No newline at end of file -- cgit v1.2.3