@@ -51,7 +51,7 @@ def __init__(self, root, title) -> None:
51
51
52
52
53
53
54
- # some constants
54
+
55
55
self .speed = 0.2
56
56
self .N = 10
57
57
self .colours = ['dodgerblue' for i in range (self .N )]
@@ -87,12 +87,11 @@ def slide_function(self):
87
87
def shuffle (self ):
88
88
self .canvas .delete ('all' )
89
89
self .data = np .linspace (5 ,400 ,self .N ,dtype = np .uint16 )
90
-
91
90
np .random .shuffle (self .data )
92
91
self .display (self .N ,self .data ,self .colours )
93
92
94
93
95
- ''' bubble sort'''
94
+ # ---------------button selection of sorting algos---------------------------
96
95
def bubble (self ):
97
96
if self .st ['bubble' ] is False :
98
97
self .st ['bubble' ] = True
@@ -112,7 +111,6 @@ def bubble(self):
112
111
self .bs .config (style = 'info.TButton' )
113
112
114
113
115
- ''' merge sort'''
116
114
def merge (self ):
117
115
if self .st ['merge' ] is False :
118
116
self .st ['merge' ] = True
@@ -132,7 +130,6 @@ def merge(self):
132
130
self .ms .config (style = 'info.TButton' )
133
131
134
132
135
- ''' quick sort'''
136
133
def quick (self ):
137
134
if self .st ['quick' ] is False :
138
135
self .st ['quick' ] = True
@@ -152,7 +149,6 @@ def quick(self):
152
149
self .qs .config (style = 'info.TButton' )
153
150
154
151
155
- ''' selection sort'''
156
152
def selection (self ):
157
153
if self .st ['selection' ] is False :
158
154
self .st ['selection' ] = True
@@ -172,7 +168,6 @@ def selection(self):
172
168
self .ss .config (style = 'info.TButton' )
173
169
174
170
175
- ''' insertion sort'''
176
171
def insertion (self ):
177
172
if self .st ['insertion' ] is False :
178
173
self .st ['insertion' ] = True
@@ -191,7 +186,7 @@ def insertion(self):
191
186
self .st ['insertion' ] = False
192
187
self .Is .config (style = 'info.TButton' )
193
188
194
-
189
+ # -----------------------------------------------------------
195
190
def start (self ):
196
191
if self .st ['bubble' ] is True :
197
192
for i in range (self .N - 1 ):
@@ -228,7 +223,7 @@ def start(self):
228
223
self .display (self .N ,self .data ,['yellow' if a == min_index or a == i else 'green' if a <= i else 'dodgerblue' for a in range (self .N )])
229
224
time .sleep (self .speed )
230
225
if self .data [min_index ]> self .data [j ]:
231
- self .display (self .N ,self .data ,['red' if a == min_index or a == i else 'green' if a <= i else 'dodgerblue' for a in range (self .N )])
226
+ self .display (self .N ,self .data ,['red' if a == min_index or a == j else 'green' if a <= i else 'dodgerblue' for a in range (self .N )])
232
227
time .sleep (self .speed )
233
228
min_index = j
234
229
if min_index != i :
@@ -251,7 +246,7 @@ def start(self):
251
246
messagebox .showerror ("Algorithm Visualizer" , "You didn't select any sorting algorithm" )
252
247
253
248
254
- # -----------merge sort-------------------------------------
249
+ # -----------merge sort algo -------------------------------------
255
250
256
251
def mergesort (self ,a ,front ,last ):
257
252
if front < last :
@@ -293,7 +288,7 @@ def mergesort(self,a,front,last):
293
288
self .display (self .N ,self .data ,['dodgerblue' for _ in range (self .N )])
294
289
time .sleep (self .speed )
295
290
296
- #-------------------------------------------------- quick sort---------------
291
+ #-----------------------------quick sort algo ---------------
297
292
298
293
def partition (self ,a ,i ,j ):
299
294
'''
@@ -330,9 +325,8 @@ def quicksort(self,a,i,j):
330
325
self .quicksort (a ,x + 1 ,j )
331
326
#--------------------------------------------------
332
327
328
+ if __name__ == '__main__' :
329
+ win = Style (theme = 'darkly' ).master
330
+ obj = window (win , 'Sorting Algorithm Visualizer' )
333
331
334
-
335
- win = Style (theme = 'darkly' ).master
336
- obj = window (win , 'Sorting Algorithm Visualizer' )
337
-
338
- win .mainloop ()
332
+ win .mainloop ()
0 commit comments