gokaymeydan commited on
Commit
e1b5212
·
1 Parent(s): 216cc42

update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -0
main.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from algorithms import insertion_sort
2
+
3
+ my_list = [5, 2, 4, 6, 1, 3]
4
+ steps = insertion_sort(my_list)
5
+ prev = None
6
+
7
+
8
+ def print_step(step, prev_step=None):
9
+ for i, num in enumerate(step):
10
+ bar = "█" * num
11
+ if prev_step and prev_step[i] != num:
12
+ print(f"{num:>2} {bar} <- shifted")
13
+ else:
14
+ print(f"{num:>2} {bar}")
15
+ print("-" * 20)
16
+
17
+
18
+ for i, step in enumerate(steps):
19
+ print(f"Step {i + 1}: {step}")
20
+ print_step(step, prev)
21
+ prev = step