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