summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinternetlandlord <f.fredhenry@gmail.com>2022-10-19 18:43:07 +0000
committerinternetlandlord <f.fredhenry@gmail.com>2022-10-19 18:43:07 +0000
commit27170a41d9cf47a8048bccb040fdb287b8af7bcc (patch)
treeacadc79d5497dfa37e2b58e20835811c02462917
parentab1b6c681ff8f0e4a468bec4d35caff75f9a44b3 (diff)
Added quick-sort algorithm and verified function. Updated README to reflect chosen algos
-rw-r--r--README.md9
-rwxr-xr-xquick-sort.py45
2 files changed, 54 insertions, 0 deletions
diff --git a/README.md b/README.md
index 0e55372..98e11ab 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,15 @@ science algorithms with file manipulation (using CSV files of random numbers).
The functional file contains I/O functions for ingressing and egressing data.
+### Algos covered:
+* Selection Sort
+* Insertion Sort
+* Quick Sort
+* Bubble Sort
+* Merge Sort
+
+More to come!
+
###### inputout.py
* Contains functions that are imported into algorithm scripts for ingressing/
exporting data to csv
diff --git a/quick-sort.py b/quick-sort.py
new file mode 100755
index 0000000..966d550
--- /dev/null
+++ b/quick-sort.py
@@ -0,0 +1,45 @@
+#!/bin/python3
+
+# ---------- title
+
+
+
+# ---------- Imported modules
+import inputoutput as io
+import csv
+import sys
+
+
+# ---------- Main
+target = sys.argv[1]
+
+# ingress of data
+numdata = io.ingressCSV(target)
+
+# quick sort algorithm, defined as a function (to be called recursively)
+def quickSort(data):
+ if(len(data)>1):
+ pivot = int(len(data)/2)
+ vcomp = data[pivot]
+
+ leftmost = [i for i in data if i < vcomp]
+ middie = [i for i in data if i == vcomp]
+ ritemost = [i for i in data if i > vcomp]
+
+ # recursively calling the quickSort function
+ recursor = quickSort(leftmost) + middie + quickSort(ritemost)
+ return recursor
+ else:
+ return data
+
+# running quicksort against the ingressed data
+numdata = quickSort(numdata)
+
+#FIXME: try using a separate list initialization if problems encountered
+#writedata = quiskSort(numdata)
+#io.egressCSV(writedata,target)
+
+
+# finishing up
+print("Sort complete, writing to file!")
+io.egressCSV(numdata,target)