From cbd1182b1a006544bac436b3d955ddc034ad5109 Mon Sep 17 00:00:00 2001 From: internetlandlord Date: Mon, 17 Oct 2022 20:46:38 +0000 Subject: Created a selection sort algorithm as a proof of concept. n^2 complexity, so grab a coffee if you decide to run it against a large array! --- selection-sort.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 selection-sort.py (limited to 'selection-sort.py') diff --git a/selection-sort.py b/selection-sort.py new file mode 100755 index 0000000..c41c86e --- /dev/null +++ b/selection-sort.py @@ -0,0 +1,32 @@ +#!/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) + +# selection sort algorithm +for i in range(len(numdata)): + mindex = i + + for j in range(i+1, len(numdata)): + if numdata[mindex] > numdata[j]: + mindex = j + + # updating values - trying without simulatenous assignment + numdata[i], numdata[mindex] = numdata[mindex], numdata[i] + +# finishing up +print("writing to file") +io.egressCSV(numdata,target) -- cgit v1.2.3