summaryrefslogtreecommitdiff
path: root/reverse-selection-sort.py
blob: a085366d7fda86aaf4789557776f65a0566efc5c (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
30
31
32
33
#!/bin/python3

# ---------- Selection Sort
# Python implementation of the selection sort algorithm
# n^n complexity, so it will start to chug on larger datasets.


# ---------- Imported modules
import inputoutput as io
import csv
import sys


# ---------- Main

# ingress of data
target = sys.argv[1]
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]:#FIXME: changing comparator to reverse function
            mindex = j

    # updating values using simultaneous assignments
    numdata[i], numdata[mindex] =  numdata[mindex], numdata[i]

# finishing up
print("Sort complete, writing to file!")
io.egressCSV(numdata,target)