-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathmain.py
64 lines (58 loc) · 2.46 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
from src.data import DataSeq
from src.bubblesort import BubbleSort
from src.bucketsort import BucketSort
from src.combsort import CombSort
from src.cyclesort import CycleSort
from src.heapsort import HeapSort
from src.insertionsort import InsertionSort
from src.mergesort import MergeSort
from src.monkeysort import MonkeySort
from src.quicksort import QuickSort
from src.radixsort import RadixSort
from src.selectionsort import SelectionSort
from src.shellsort import ShellSort
import argparse
def parse_args():
parser=argparse.ArgumentParser(description="Sort Visulization")
parser.add_argument('-l','--length',type=int,default=64)
parser.add_argument('-i','--interval',type=int,default=1)
parser.add_argument('-t','--sort-type',type=str,default='BubbleSort',
choices=["BubbleSort","BucketSort","CombSort",
"CycleSort","HeapSort","InsertionSort",
"MergeSort","MonkeySort","QuickSort",
"RadixSort","SelectionSort","ShellSort",])
parser.add_argument('-r','--resample', action='store_true')
parser.add_argument('-s','--sparse', action='store_true')
parser.add_argument('--no-record', action='store_true')
parser.add_argument('--silent', action='store_true')
parser.add_argument('--sound-interval', type=int, default=16)
args=parser.parse_args()
return args
if __name__ == "__main__":
args = parse_args()
MAXLENGTH=1000
Length = args.length if args.length<MAXLENGTH else MAXLENGTH
Interval = args.interval
SortType = args.sort_type
Resampling = args.resample
Sparse = args.sparse
NoRecord = args.no_record
NoSound = args.silent
sound_interval = args.sound_interval
try:
SortMethod=eval(SortType)
except:
raise RuntimeError("Sort Type Not Found! Please Check if %s Exists or Not!"%SortType)
exit()
if not NoSound and sound_interval*10<Interval:
raise UserWarning("UserWarning: sound interval too small")
ds=DataSeq(Length, time_interval=Interval,
sort_title=SortType,
is_resampling=Resampling,
is_sparse=Sparse,
record=not NoRecord,
sound=not NoSound, sound_interval=sound_interval)
ds.StartTimer()
SortMethod(ds)
ds.StopTimer()
ds.Hold()