-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
38 lines (30 loc) · 1.01 KB
/
Copy pathtests.py
File metadata and controls
38 lines (30 loc) · 1.01 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
from algorithms import (
bubble_sort,
selection_sort,
insertion_sort,
merge_sort,
quick_sort,
linear_search,
binary_search,
)
def run_algorithm(algorithm, data, target=None):
last_state = None
if target is None:
for step in algorithm(data):
last_state = step
else:
for step in algorithm(data, target):
last_state = step
return last_state
def main():
sample = [5, 3, 8, 1, 2, 7]
print("Original:", sample)
print("Bubble:", run_algorithm(bubble_sort, sample)["data"])
print("Selection:", run_algorithm(selection_sort, sample)["data"])
print("Insertion:", run_algorithm(insertion_sort, sample)["data"])
print("Merge:", run_algorithm(merge_sort, sample)["data"])
print("Quick:", run_algorithm(quick_sort, sample)["data"])
print("Linear Search:", run_algorithm(linear_search, sample, 8)["message"])
print("Binary Search:", run_algorithm(binary_search, sample, 8)["message"])
if __name__ == "__main__":
main()