diff options
author | internetlandlord <f.fredhenry@gmail.com> | 2022-10-31 16:20:32 -0500 |
---|---|---|
committer | internetlandlord <f.fredhenry@gmail.com> | 2022-10-31 16:20:32 -0500 |
commit | 6c7a50854c73575d53e93a584d6d9848493adda3 (patch) | |
tree | b78f97fe57f820e0b1ffa94bc2e9c961e37a73e1 | |
parent | b8a2b8d9aee28d5ef1753d8ebdfea480b9603c48 (diff) |
Created the first of the reverse sorting algorithms using bubble sort. Has a separate filename appendation(?)
-rwxr-xr-x | reverse-bubble-sort.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/reverse-bubble-sort.py b/reverse-bubble-sort.py new file mode 100755 index 0000000..109ab52 --- /dev/null +++ b/reverse-bubble-sort.py @@ -0,0 +1,30 @@ +#!/bin/python3 + +# ---------- REVERSE 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 +import csv +import sys + + +# ---------- Main +target = sys.argv[1] + +# ingress of data +numdata = io.ingressCSV(target) + +# bubble sort operation +for i in range(len(numdata)): + for j in range(0,len(numdata)-i-1): + if numdata[j] < numdata[j+1]: #FIXME: flipped comparative op + numdata[j], numdata[j+1] = numdata[j+1], numdata[j] + +# finishing up, appending "-bubblesorted" to CSV +target = target[:-4]+"-REV-bubblesorted"+target[-4:] +print("Sorting complete! Writing to file.") +io.egressCSV(numdata,target) |