aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2020-01-30 16:15:22 -0600
committerRossTheRoss <msattr@gmail.com>2020-01-30 16:15:22 -0600
commitee9729a8d85028e1689868c9b58d49ce9df5ea8f (patch)
tree06960177d3a81bd078672f4d27f8754664a469bc
parentSpacing? (diff)
downloadhomework-ee9729a8d85028e1689868c9b58d49ce9df5ea8f.tar
homework-ee9729a8d85028e1689868c9b58d49ce9df5ea8f.tar.gz
homework-ee9729a8d85028e1689868c9b58d49ce9df5ea8f.tar.bz2
homework-ee9729a8d85028e1689868c9b58d49ce9df5ea8f.tar.lz
homework-ee9729a8d85028e1689868c9b58d49ce9df5ea8f.tar.xz
homework-ee9729a8d85028e1689868c9b58d49ce9df5ea8f.tar.zst
homework-ee9729a8d85028e1689868c9b58d49ce9df5ea8f.zip
Make Python thing in Python
-rw-r--r--csci4041/TEST.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/csci4041/TEST.py b/csci4041/TEST.py
new file mode 100644
index 0000000..bc9ae7d
--- /dev/null
+++ b/csci4041/TEST.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