From 05272438359e6696e62c6363082d795d5c95219a Mon Sep 17 00:00:00 2001 From: internetlandlord Date: Thu, 3 Nov 2022 21:25:36 +0000 Subject: Adjusted more appending names, added reverse selection sort algorithm --- reverse-selection-sort.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 reverse-selection-sort.py (limited to 'reverse-selection-sort.py') 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) -- cgit v1.2.3