Sorting can be defined as arranging list, number, or any times in an systematic way in a certain order of sequence having comparable properties. In simple word Sorting is the process to rearrange the items of a given list in Ascending Order/Descending Order.
Previously in our Computer Graphics Project blog we have discussed about Bucket sort program a sorting program. In that Computer Graphics Project program the user uses to provide two input array to store and show the sorting process and result, while in this project the sorting is show dynamically with Circles representing the input list to sort.
Description: The underlying concept of sorting algorithm includes the comparisons, swapping of elements, and assignments. The DSAV ( Dynamic Sorting Algorithm Visualizer ), Visualizes the Bubble Sort Algorithm. In this algorithm, comparisons starts from the first two elements of the array and finding the largest item and move (or bubble) it to the top. With each subsequent iteration, find the next largest item and bubble it up towards the top of the array.
This DSA Visualizer depicts the swapping of elements by swapping the circles (which are the items of the array in our case), for each item different radii of circle is generated according to the value of the item. This swapping process occurs for at the max of n iterations. Thus at the end of nth iteration, the array of elements are sorted in the ascending order which is the desired output of the DSAV. Below is the logic or say short algorithm of the Dynamic Sorting Algorithm Visualizer Computer Graphics Project.
Logic of sorting :
If not in the process of swapping of 2
circles then only get 2 new circles to swap.
While the counter_i < 10
While counter_j <9
If the a[counter_j] >
a[counter_j]
Swap 2 circles
Once exchanged goto swap
Increment counter_j
Increment counter_i
Swap:
Print which circles are getting swapped.
Call swap_circles
function again with counter_j and counter_j+1 values.
Mark the end of the
function sort.
Usages: First the window generate will ask 'press enter to continue.....' ; press enter key
Menu is written with what to do on the screen it self.
Following is what keyboard will do after it get pressed -
s : To start sorting
r : To randomizes the sorted list
esc : Exit
Project Code and Report for the program :