|
4 | 4 | import os
|
5 | 5 | import signal
|
6 | 6 | from types import FrameType
|
7 |
| -from typing import List, Union, Callable |
| 7 | +from typing import List, Union |
8 | 8 | from rich.console import Console
|
| 9 | +from pyfiglet import figlet_format |
9 | 10 |
|
10 | 11 | console: Console = Console()
|
11 | 12 |
|
@@ -84,59 +85,67 @@ def exit_gracefully(signal: signal.Signals, frame: Union[FrameType, None]) -> No
|
84 | 85 |
|
85 | 86 |
|
86 | 87 | def main() -> None:
|
87 |
| - options: dict[str, Union[str, Callable[[], None]]] = { |
| 88 | + options: dict[str, str] = { |
88 | 89 | '1': 'bubble_sort',
|
89 | 90 | '2': 'insertion_sort',
|
90 | 91 | '3': 'selection_sort',
|
| 92 | + '4': 'quick_sort', |
| 93 | + '5': 'merge_sort', |
| 94 | + '6': 'counting_sort', |
| 95 | + '7': 'Linked_List_Merge_Sort', |
| 96 | + '8': 'Finish testing', |
| 97 | + } |
| 98 | + |
| 99 | + quick_sort_options: dict[str, str] = { |
91 | 100 | 'A': 'first',
|
92 | 101 | 'B': 'last',
|
93 | 102 | 'C': 'medianOfThree',
|
94 | 103 | 'D': 'Random',
|
95 |
| - '5': 'merge_sort', |
96 |
| - '6': 'counting_sort', |
97 |
| - '7': 'Linked_List_Merge_Sort', |
98 |
| - '8': lambda: console.print("Ending the loop.", style="bold green") |
99 | 104 | }
|
100 | 105 |
|
101 | 106 | signal.signal(signal.SIGINT, exit_gracefully)
|
102 | 107 |
|
| 108 | + text: str = "Sorting Algorithms" |
| 109 | + ascii_art = figlet_format(text, font="slant") |
| 110 | + console.print(ascii_art, style="bold cyan") |
| 111 | + |
103 | 112 | while True:
|
104 |
| - console.print("Enter the number corresponding to the sorting algorithm you want to test:") |
105 |
| - |
| 113 | + console.print("Enter the number corresponding to the sorting algorithm you want to test:\n", style="bold #00AAA6 u") |
106 | 114 | for key, value in options.items():
|
107 |
| - if key.isdigit() and int(key) >= 1 and int(key) <= 7: |
| 115 | + if key == '8': |
| 116 | + console.print(f"[green bold]{key}.[/green bold] {value}", style="b red") |
| 117 | + else: |
108 | 118 | console.print(f"[green bold]{key}.[/green bold] {value}")
|
| 119 | + |
109 | 120 |
|
110 |
| - console.print("[green bold]8.[/green bold] Finish testing", style="red") |
111 |
| - console.print(" Choose from [green bold](1 - 6)[green bold]") |
| 121 | + console.print(f" Choose from [green bold](1 - {len(options)})[green bold]") |
112 | 122 | console.print("\n" + "-" * 40 + "\n", style="bold cyan")
|
113 | 123 |
|
114 | 124 | choice: str = input()
|
115 | 125 |
|
116 | 126 | if choice == '4':
|
117 | 127 | while True:
|
118 | 128 | console.print("Choose the version of Quick Sort:")
|
119 |
| - console.print("[green bold]A.[/green bold] First Element Pivot") |
120 |
| - console.print("[green bold]B.[/green bold] Last Element Pivot") |
121 |
| - console.print("[green bold]C.[/green bold] Median of Three Pivot") |
122 |
| - console.print("[green bold]D.[/green bold] Random Pivot") |
| 129 | + |
| 130 | + for key, value in quick_sort_options.items(): |
| 131 | + console.print(f"[green bold]{key}.[/green bold] {value}", style="") |
| 132 | + |
123 | 133 | console.print("[green bold]E.[/green bold] end Quick Sort chise\n", style="red")
|
124 |
| - |
125 | 134 | quick_sort_choice: str = input("Enter your choice (a/A/ b/B c/C d/D e/E): ").upper()
|
126 | 135 |
|
127 | 136 | if quick_sort_choice in ['A', 'B', 'C', 'D', 'E']:
|
128 | 137 | if(quick_sort_choice == 'E'):
|
129 | 138 | break
|
130 | 139 | else:
|
131 |
| - pivot_name: str = options[quick_sort_choice] |
| 140 | + pivot_name: str = quick_sort_options[quick_sort_choice] |
132 | 141 | test_Quick_Sort(quick_sort_choice, pivot_name)
|
133 | 142 |
|
134 | 143 | else:
|
135 | 144 | console.print("Invalid choice. Please enter A, B, C, or D.", style="bold red")
|
136 | 145 | else:
|
137 | 146 | if choice in options:
|
138 | 147 | if choice == '8':
|
139 |
| - options[choice]() |
| 148 | + console.print("Ending the loop.", style="bold green") |
140 | 149 | cleanup_test_files(TEST_FILES)
|
141 | 150 | break
|
142 | 151 | else:
|
|
0 commit comments