blob: c166830362030abc5c7748e387f93c066ecbe95a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/bin/python3
# ---------- REVERSE Bubble Sort Algorithm
# Bubble sort in reverse (greatest --> least)
# Very simple implementation due to straightforward
# layout of algorithm
# ---------- 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]+"-reverse-bubble"+target[-4:]
print("Sorting complete! Writing to file.")
io.egressCSV(numdata,target)
|