Create insertionSort.py
Browse files- insertionSort.py +15 -0
insertionSort.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
from colors import *
|
3 |
+
|
4 |
+
|
5 |
+
def insertion_sort(data, draw_data, time_tick):
|
6 |
+
for i in range(len(data)):
|
7 |
+
temp = data[i]
|
8 |
+
j = i
|
9 |
+
while j > 0 and temp < data[j-1]:
|
10 |
+
data[j] = data[j-1]
|
11 |
+
j -= 1
|
12 |
+
data[j] = temp
|
13 |
+
draw_data(data, [LIGHT_GREEN if x == j or x == i else BLUE for x in range(len(data))])
|
14 |
+
time.sleep(time_tick)
|
15 |
+
draw_data(data, [BLUE for x in range(len(data))])
|