1212from Algorithms .selection_sort import selection_sort
1313from Algorithms .insertion_sort import insertion_sort
1414from Algorithms .merge_sort import merge_sort
15+ from Algorithms .heap_sort import heap_sort
1516from Display .display import update_display , show
1617
1718pygame .init ()
@@ -78,6 +79,11 @@ def main(win):
7879 else :
7980 button_selection_sort .background_color = DARK_BUTTON
8081
82+ if (button_heap_sort .check () == True ):
83+ button_heap_sort .background_color = LIGHT_BUTTON
84+ else :
85+ button_heap_sort .background_color = DARK_BUTTON
86+
8187 if (button_merge_sort .check () == True ):
8288 button_merge_sort .background_color = LIGHT_BUTTON
8389 else :
@@ -143,13 +149,19 @@ def main(win):
143149
144150 if (algorithm == "Insertion Sort" ):
145151 start_time = time .time ()
146- numswaps = insertion_sort (win , height , color_height , 0 , algorithm , number_of_elements , speed )
152+ current_numswaps = insertion_sort (win , height , color_height , 0 , algorithm , number_of_elements , speed )
147153 elapsed_time = time .time () - start_time
148154 update_display (win , height , color_height , current_numswaps , algorithm , number_of_elements , speed , elapsed_time , False )
149155
150156 if (algorithm == "Selection Sort" ):
151157 start_time = time .time ()
152- numswaps = selection_sort (win , height , color_height , 0 , algorithm , number_of_elements , speed )
158+ current_numswaps = selection_sort (win , height , color_height , 0 , algorithm , number_of_elements , speed )
159+ elapsed_time = time .time () - start_time
160+ update_display (win , height , color_height , current_numswaps , algorithm , number_of_elements , speed , elapsed_time , False )
161+
162+ if (algorithm == "Heap Sort" ):
163+ start_time = time .time ()
164+ current_numswaps = heap_sort (height , color_height , win , 0 , algorithm , number_of_elements , speed )
153165 elapsed_time = time .time () - start_time
154166 update_display (win , height , color_height , current_numswaps , algorithm , number_of_elements , speed , elapsed_time , False )
155167
@@ -174,6 +186,9 @@ def main(win):
174186 if (button_merge_sort .check () == True ):
175187 algorithm = "Merge Sort"
176188
189+ if (button_heap_sort .check () == True ):
190+ algorithm = "Heap Sort"
191+
177192 if (button_20 .check () == True ):
178193 number_of_elements = 20
179194
0 commit comments