summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinternetlandlord <f.fredhenry@gmail.com>2022-11-03 21:25:36 +0000
committerinternetlandlord <f.fredhenry@gmail.com>2022-11-03 21:25:36 +0000
commit05272438359e6696e62c6363082d795d5c95219a (patch)
treec6f0d9833c400be86c195a060c26a6c7fa48bf3c
parent4abdc0d451d254cdfcff42eec1f3998afbf8fa49 (diff)
Adjusted more appending names, added reverse selection sort algorithm
-rwxr-xr-xinsertion-sort.py2
-rwxr-xr-xmerge-sort.py2
-rwxr-xr-xreverse-selection-sort.py33
3 files changed, 35 insertions, 2 deletions
diff --git a/insertion-sort.py b/insertion-sort.py
index 6aa620a..caadc6f 100755
--- a/insertion-sort.py
+++ b/insertion-sort.py
@@ -31,6 +31,6 @@ def insertionSort(data):
insertionSort(numdata)
# wrapping up and appending "-insertionsorted" to CSV
-target = target[:-4]+"-insertionsorted"+target[-4:]
+target = target[:-4]+"-insertion"+target[-4:]
print("Sorting done! Writing to file.")
io.egressCSV(numdata,target)
diff --git a/merge-sort.py b/merge-sort.py
index 2464e03..1653597 100755
--- a/merge-sort.py
+++ b/merge-sort.py
@@ -57,6 +57,6 @@ def mergeSort(data):
mergeSort(numdata)
# finishing up and appending "-mergesorted" to CSV
-target = target[:-4]+"-mergesorted"+target[-4:]
+target = target[:-4]+"-merge"+target[-4:]
print("Sorting done, writing to file!")
io.egressCSV(numdata,target)
diff --git a/reverse-selection-sort.py b/reverse-selection-sort.py
new file mode 100755
index 0000000..a085366
--- /dev/null
+++ b/reverse-selection-sort.py
@@ -0,0 +1,33 @@
+#!/bin/python3
+
+# ---------- Selection Sort
+# Python implementation of the selection sort algorithm
+# n^n complexity, so it will start to chug on larger datasets.
+
+
+# ---------- Imported modules
+import inputoutput as io
+import csv
+import sys
+
+
+# ---------- Main
+
+# ingress of data
+target = sys.argv[1]
+numdata = io.ingressCSV(target)
+
+# selection sort algorithm
+for i in range(len(numdata)):
+ mindex = i
+
+ for j in range(i+1, len(numdata)):
+ if numdata[mindex] < numdata[j]:#FIXME: changing comparator to reverse function
+ mindex = j
+
+ # updating values using simultaneous assignments
+ numdata[i], numdata[mindex] = numdata[mindex], numdata[i]
+
+# finishing up
+print("Sort complete, writing to file!")
+io.egressCSV(numdata,target)