Bubble sort visualizer using PyGame
In this article we will see how we can visualize the bubble sort algorithm using PyGame i.e when the pygame application get started we can see the unsorted bars with different heights and when we click space bar key it started getting arranging in bubble sort manner i.e after every iteration maximum value element should come at last.
Bubble Sort is a simple algorithm which is used to sort a given set of n elements provided in form of an array with n number of elements. Bubble Sort compares all the element one by one and sort them based on their values.
Implementation steps :
1. Create a main window
2. Fill the main window with black color
3. Create a method to show the list of bar with specific gap in between them
4. Get the keys input from the user
5. If space bar is pressed start the sorting process
6. Implement bubble sort algorithm on the list
7. After every internal iteration fill the screen with black color and call the show method to show the iterated list in the form of bar.
Below is the implementation