-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (56 loc) · 1.82 KB
/
main.py
File metadata and controls
70 lines (56 loc) · 1.82 KB
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
import sys
import os
from strategy.sort_strategy import SortStrategy
from algorithms.quick_sort import QuickSort
from algorithms.merge_sort import MergeSort
from algorithms.bubble_sort import BubbleSort
from algorithms.selection_sort import SelectionSort
strategy_selected = None
array_selected = []
def display_choices():
global strategy_selected
global array_selected
print("Select Sorting Algorithm")
print("------------------------------------")
print("[1] Quick Sort")
print("[2] Merge Sort")
print("[3] Bubble Sort")
print("[4] Selection Sort")
print("\n")
strategy_selected = int(input("Select Sorting: "))
range_elements = int(input("Enter Number of Elements: "))
for i in range(0, range_elements):
ele = int(input("Enter Element {}: ".format(i)))
array_selected.append(ele)
def main():
global strategy_selected
global array_selected
os.system('cls')
display_choices()
if strategy_selected == 1:
title = "Quick Sort"
sort = SortStrategy(QuickSort)
elif strategy_selected == 2:
title = "Merge Sort"
sort = SortStrategy(MergeSort)
elif strategy_selected == 3:
title = "Bubble Sort"
sort = SortStrategy(BubbleSort)
elif strategy_selected == 4:
title = "Selection Sort"
sort = SortStrategy(SelectionSort)
else:
title = "Quick Sort"
sort = SortStrategy(QuickSort)
sorted_array = sort.do_sort(array_selected)
print("\nAlgorithm: {}".format(title))
print("Unsorted List: {}".format(array_selected))
print("Sorted List: {}".format(sorted_array))
print("\n")
is_continue = input("Try Another?[Y/N]: ")
if is_continue.lower() == 'y':
strategy_selected = None
array_selected = []
main()
if __name__ == '__main__':
main()