Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c6fe232

Browse files
committed
selection sort updated
1 parent 11ee0d4 commit c6fe232

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

‎.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/test.py
22
/test2.py
3-
/seed.py
3+
/seed.py
4+
/Screenshot 2021年10月16日 021635.png

‎algo_visualizer.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, root, title) -> None:
5151

5252

5353

54-
# some constants
54+
5555
self.speed=0.2
5656
self.N=10
5757
self.colours=['dodgerblue' for i in range(self.N)]
@@ -87,12 +87,11 @@ def slide_function(self):
8787
def shuffle(self):
8888
self.canvas.delete('all')
8989
self.data=np.linspace(5,400,self.N,dtype=np.uint16)
90-
9190
np.random.shuffle(self.data)
9291
self.display(self.N,self.data,self.colours)
9392

9493

95-
''' bubble sort'''
94+
# ---------------button selection of sorting algos---------------------------
9695
def bubble(self):
9796
if self.st['bubble'] is False:
9897
self.st['bubble'] = True
@@ -112,7 +111,6 @@ def bubble(self):
112111
self.bs.config(style='info.TButton')
113112

114113

115-
''' merge sort'''
116114
def merge(self):
117115
if self.st['merge'] is False:
118116
self.st['merge'] = True
@@ -132,7 +130,6 @@ def merge(self):
132130
self.ms.config(style='info.TButton')
133131

134132

135-
''' quick sort'''
136133
def quick(self):
137134
if self.st['quick'] is False:
138135
self.st['quick'] = True
@@ -152,7 +149,6 @@ def quick(self):
152149
self.qs.config(style='info.TButton')
153150

154151

155-
''' selection sort'''
156152
def selection(self):
157153
if self.st['selection'] is False:
158154
self.st['selection'] = True
@@ -172,7 +168,6 @@ def selection(self):
172168
self.ss.config(style='info.TButton')
173169

174170

175-
''' insertion sort'''
176171
def insertion(self):
177172
if self.st['insertion'] is False:
178173
self.st['insertion'] = True
@@ -191,7 +186,7 @@ def insertion(self):
191186
self.st['insertion'] = False
192187
self.Is.config(style='info.TButton')
193188

194-
189+
# -----------------------------------------------------------
195190
def start(self):
196191
if self.st['bubble'] is True:
197192
for i in range(self.N-1):
@@ -228,7 +223,7 @@ def start(self):
228223
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)])
229224
time.sleep(self.speed)
230225
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)])
232227
time.sleep(self.speed)
233228
min_index=j
234229
if min_index!=i:
@@ -251,7 +246,7 @@ def start(self):
251246
messagebox.showerror("Algorithm Visualizer", "You didn't select any sorting algorithm")
252247

253248

254-
# -----------merge sort-------------------------------------
249+
# -----------merge sort algo-------------------------------------
255250

256251
def mergesort(self,a,front,last):
257252
if front<last:
@@ -293,7 +288,7 @@ def mergesort(self,a,front,last):
293288
self.display(self.N,self.data,['dodgerblue' for _ in range(self.N)])
294289
time.sleep(self.speed)
295290

296-
#--------------------------------------------------quick sort---------------
291+
#-----------------------------quick sort algo---------------
297292

298293
def partition(self,a,i,j):
299294
'''
@@ -330,9 +325,8 @@ def quicksort(self,a,i,j):
330325
self.quicksort(a,x+1,j)
331326
#--------------------------------------------------
332327

328+
if __name__ == '__main__':
329+
win = Style(theme='darkly').master
330+
obj = window(win, 'Sorting Algorithm Visualizer')
333331

334-
335-
win = Style(theme='darkly').master
336-
obj = window(win, 'Sorting Algorithm Visualizer')
337-
338-
win.mainloop()
332+
win.mainloop()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /