summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinternetlandlord <f.fredhenry@gmail.com>2022-10-17 20:46:38 +0000
committerinternetlandlord <f.fredhenry@gmail.com>2022-10-17 20:46:38 +0000
commitcbd1182b1a006544bac436b3d955ddc034ad5109 (patch)
tree489530522c707bb9dcab7fca259fa4de53b9b0d8
parent93ca9c5856888c373977c8901a28b432bfa17e95 (diff)
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!
-rwxr-xr-xselection-sort.py32
-rwxr-xr-xtester.py25
2 files changed, 32 insertions, 25 deletions
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)
diff --git a/tester.py b/tester.py
deleted file mode 100755
index e44982f..0000000
--- a/tester.py
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/python3
-
-# ---------- Testing script
-# Uses command line arguments to call functions
-
-
-# ---------- Imported modules
-
-import inputoutput as io
-import csv
-import sys
-
-# ---------- Main
-
-# command line args passed to variables
-rspan = int(sys.argv[1])
-rlim = int(sys.argv[2])
-ofile =sys.argv[3]
-
-print("Your params:\n")
-print("\tCSV size: {}".format(rspan))
-print("\tNumber range: 1 - {}".format(rlim))
-print("\tOutput file: {}".format(ofile))
-print("\nGenerating a CSV!")
-io.generateCSV(rspan,rlim,ofile)