1- from algorithms import bubble_sort
1+ from algorithms import bubble_sort , selection_sort
22import tkinter as tk
33import random
44
@@ -24,7 +24,7 @@ def draw_array(array, color_array):
2424 root .update_idletasks ()
2525
2626#Function to Start Sorting using Bubble Sort
27- def start_sort ():
27+ def start_bubble_sort ():
2828 color_array = ['blue' for _ in range (len (array ))]
2929 for arr , i , j in bubble_sort (array ):
3030 color_array [i ] = 'red'
@@ -33,12 +33,30 @@ def start_sort():
3333 color_array [i ] = 'blue'
3434 color_array [j ] = 'blue'
3535
36+ #Function to Start Sorting using Selection Sort
37+ def start_selection_sort ():
38+ color_array = ['blue' for _ in range (len (array ))]
39+ for arr , i , j in selection_sort (array ):
40+ color_array [i ] = 'red'
41+ color_array [j ] = 'red'
42+ draw_array (arr , color_array )
43+ color_array [i ] = 'blue'
44+ color_array [j ] = 'blue'
45+
3646#Random Array
3747array = [random .randint (10 , 100 ) for _ in range (50 )]
3848
49+ #Create a Frame for the Buttons
50+ button_frame = tk .Frame (root )
51+ button_frame .pack (pady = 10 )
52+
3953#'Start Bubble Sort' Button
40- start_button = tk .Button (root , text = "Start Bubble Sort" , command = start_sort )
41- start_button .pack (pady = 10 )
54+ start_bubble_button = tk .Button (button_frame , text = "Start Bubble Sort" , command = start_bubble_sort )
55+ start_bubble_button .pack (side = tk .LEFT , padx = 5 )
56+
57+ #'Start Selection Sort' Button
58+ start_selection_button = tk .Button (button_frame , text = "Start Selection Sort" , command = start_selection_sort )
59+ start_selection_button .pack (side = tk .LEFT , padx = 5 )
4260
4361color_array = ['blue' for _ in range (len (array ))]
4462draw_array (array , color_array )
0 commit comments