@@ -43,6 +43,24 @@ def changeBars(self, up):
4343 self .bars -= 10
4444 self .genList ()
4545
46+ def setAlgo (self , key = False ):
47+ self .algorithms = {
48+ "Bubble Sort" : self .bubbleSort ,
49+ "Insertion Sort" : self .insertionSort ,
50+ "Merge Sort" : self .mergeSort ,
51+ }
52+ key_to_name = {
53+ pygame .K_b : "Bubble Sort" ,
54+ pygame .K_i : "Insertion Sort" ,
55+ pygame .K_m : "Merge Sort" ,
56+ }
57+ self .algo_keys = key_to_name .keys ()
58+ if not key :
59+ key = list (self .algo_keys )[0 ]
60+ name = key_to_name [key ]
61+ self .algo_name = name
62+ self .algo = self .algorithms [name ]
63+
4664 # Visualization
4765 def update (self ):
4866 self .gen = self .algo ()
@@ -127,26 +145,6 @@ def drawList(self, clear_bg=False):
127145 )
128146 pygame .display .update ()
129147
130- # Algorithm Methods
131-
132- def setAlgo (self , key = False ):
133- self .algorithms = {
134- "Bubble Sort" : self .bubbleSort ,
135- "Insertion Sort" : self .insertionSort ,
136- "Merge Sort" : self .mergeSort ,
137- }
138- key_to_name = {
139- pygame .K_b : "Bubble Sort" ,
140- pygame .K_i : "Insertion Sort" ,
141- pygame .K_m : "Merge Sort" ,
142- }
143- self .algo_keys = key_to_name .keys ()
144- if not key :
145- key = list (self .algo_keys )[0 ]
146- name = key_to_name [key ]
147- self .algo_name = name
148- self .algo = self .algorithms [name ]
149-
150148 # Algorithms
151149 def bubbleSort (self ):
152150 for i in range (self .len_list - 1 ):
@@ -173,7 +171,7 @@ def insertionSort(self):
173171 i -= 1
174172 yield True
175173
176- # TODO add Merge Sort descending functionality
174+ # TODO descending functionality
177175 def mergeSort (self , start = 0 , end = False ):
178176 if not end :
179177 end = self .len_list
@@ -213,8 +211,8 @@ def mergeSort(self, start=0, end=False):
213211
214212 yield True
215213
216- # TODO add Heap Sort
217- # TODO add Quick Sort
214+ # TODO Heap Sort
215+ # TODO Quick Sort
218216
219217 # Main function
220218 def run (self ):
0 commit comments