summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinternetlandlord <f.fredhenry@gmail.com>2022-10-26 09:55:31 -0500
committerinternetlandlord <f.fredhenry@gmail.com>2022-10-26 09:55:31 -0500
commit030d136e851340af56c613bca75a4c58d91e8c4a (patch)
treefe86aaf40738dfbf2a5f3ddff3d0eebe6a59fecd
parent68c7b0092fcb55bec2e9fa4688ffc99649aebf83 (diff)
Refactoring/housekeeping on source code for bubble, io and insertion sort files.
-rwxr-xr-xbubble-sort.py10
-rwxr-xr-xinputoutput.py7
-rwxr-xr-xinsertion-sort.py9
3 files changed, 13 insertions, 13 deletions
diff --git a/bubble-sort.py b/bubble-sort.py
index 431a6f2..ac7237c 100755
--- a/bubble-sort.py
+++ b/bubble-sort.py
@@ -1,8 +1,10 @@
#!/bin/python3
-# ---------- title
-
-
+# ---------- Bubble Sort Algorithm
+# Python implementation of bubble sort algorithm
+# uses the csv, and inputoutput modules to import
+# CSVs and sort the numbers in a list before writing
+# to a CSV file with an appended -sorted title.
# ---------- Imported modules
import inputoutput as io
@@ -23,5 +25,5 @@ for i in range(len(numdata)):
numdata[j], numdata[j+1] = numdata[j+1], numdata[j]
# finishing up
-print("writing to file")
+print("Sorting complete! Writing to file.")
io.egressCSV(numdata,target)
diff --git a/inputoutput.py b/inputoutput.py
index 0f0b94a..dd20da6 100755
--- a/inputoutput.py
+++ b/inputoutput.py
@@ -1,7 +1,9 @@
#!/bin/python3
# ---------- inputoutput.py
-# Contains functions used for creating and intaking data
+# Contains functions used for the creating, importing and exporting
+# series of randomly-generated integers to a CSV file. This is used
+# as a module in the algo-py scripts to simply and expedite coding.
# ---------- Imported Modules
import csv
@@ -31,10 +33,11 @@ def egressCSV(row,location):
# create a new file with -sorted
location = location[:-4]+"-sorted"+location[-4:]
-
+ # open file to write
f = open(location,'w')
writehead = csv.writer(f)
+ # write the row to file and close
writehead.writerow(row)
f.close()
diff --git a/insertion-sort.py b/insertion-sort.py
index dfb7900..41a07da 100755
--- a/insertion-sort.py
+++ b/insertion-sort.py
@@ -1,6 +1,7 @@
#!/bin/python3
-# --------- Insertion sort
+# --------- Insertion Sort Algorithm
+# Implementation of algorithm in python
# --------- Imported modules
import inputoutput as io
@@ -26,12 +27,6 @@ def insertionSort(data):
# move key after element smaller than it
data[j + 1] = key
-#testarr = [99,77,44,22,11,33]
-#print(testarr)
-#insertionSort(testarr)
-#FIXME: no return argument needed!
-#print(testarr)
-
# sorting call
insertionSort(numdata)