-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (67 loc) · 2.58 KB
/
main.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
import time
import generateArrays as makeArrays
import selectionsort
import insertionsort
import newQuickSortv2
import test
def main():
if len(sys.argv) != 4:
print("Please enter the correct arguments.")
else:
arrayToSort = ''
try:
if sys.argv[3] == 's':
arrayToSort = makeArrays.generateSortedArray(int(sys.argv[2]))
elif sys.argv[3] == 'c':
arrayToSort = makeArrays.generateZeroArray(int(sys.argv[2]))
elif sys.argv[3] == 'r':
arrayToSort = makeArrays.generateRandomArray(int(sys.argv[2]))
else:
print("Please select a valid array format (s,c,r)")
return -1
except:
print("Please enter a valid number.")
return -1
if sys.argv[1] == 'q':
start = time.time()
print('Start: ' + str(start))
try:
newQuickSortv2.quickSort(arrayToSort)
except:
print("Quick sort overloaded the stack python provides and failed. (1000 stack limit)")
return -1
stop = time.time()
print('Stop: ' + str(stop))
print('Runtime: ' + str(stop - start))
if test.checkSorted(arrayToSort):
print('Data correctly sorted after running Quick Sort.')
else:
print('Data incorrectly sorted after running Quick Sort')
elif sys.argv[1] == 'i':
start = time.time()
print('Start: ' + str(start))
arrayToSort = insertionsort.insertionsort(arrayToSort)
stop = time.time()
print('Stop: ' + str(stop))
print('Runtime: ' + str(stop - start))
if test.checkSorted(arrayToSort):
print('Data correctly sorted after running Insertion Sort.')
else:
print('Data incorrectly sorted after running Insertion Sort')
elif sys.argv[1] == 's':
start = time.time()
print('Start: ' + str(start))
arrayToSort = selectionsort.selectionsort(arrayToSort)
stop = time.time()
print('Stop: ' + str(stop))
print('Runtime: ' + str(stop - start))
if test.checkSorted(arrayToSort):
print('Data correctly sorted after running Selection Sort.')
else:
print('Data incorrectly sorted after running Selection Sort')
else:
print("Please select a valid algorithm (q,i,s)")
return -1
if __name__ == "__main__":
main()