Saturday, September 24, 2011

Algorithm Simulator - Insertion Sort, Selection Sort and Bubble Sort


For the 'Design and Analysis of Algorithms' (DAA) subject in the 2nd semester of the 2nd year at SLIIT, we had to develop an application to demonstrate the usage of some algorithms. We were given a list of algorithms and we were given freedom to choose any programming language and tool for the development. 

I chose C# since I'm familiar with .NET framework than Java and Visual Studio 2008 as the IDE. The algorithms I selected were Insertion sort, Selection Sort and Bubble sort. The user should be able to provide inputs and then the application should simulate how the sorting is done. 

I used Labels to display the elements in the array and Timers to move the Labels accordingly. 

I'd like to share the source code so that those who are new to this can learn how to develop such kind of application.

To improve the user friendliness and appearance, I used an 'Outlook bar' in the application. It was an open source project where I found the code from CodeProject

Special thanks to Professor Godfrey Muganda of the Department of Computer Science, North Central College, Naperville, IL for the support provided via emails replying to my questions related to the development of this project.

These are some screen shots of the application.







-Tharindu Edirisinghe-
-SLIIT 10'-

10 comments:

Anonymous said...

i got nothing in here..

Tharindu Edirisinghe said...

??? What you mean ???

Anonymous said...

thnz bro

Anonymous said...

Can't find the code when the numbers need to swap

Tharindu Edirisinghe said...

I have used two timers for the movement of numbers. You can find the timer start method which is the time to swap the numbers.

Chamara M silva said...

when i implement my simulator i got error in selection sort.. i said that null reference exception unhandled..

it is coming from sort btn click event.. how sholud i handle it ??

code : if (S_speedup.Value != 0)
S_Timer2.Interval = 20 / S_speedup.Value;
else
S_Timer2.Interval = 20;

this.Slbl_stts.Text = "Sorting Data";



for (int i = 0; i < Slength; i++)
{
SmyLabels[i].Text = SdataArray[i].ToString();
SmyLabels[i].BackColor = Color.White;
}

Slbl_j.Location = new Point(SmyLabels[SstartingIndex].Location.X - 80, SmyLabels[SstartingIndex].Location.Y);
//lblII.Location = new Point(SmyLabels[ScurrentIndex].Location.X - 30, SmyLabels[ScurrentIndex].Location.Y);
this.Slbl_j.Visible = true;
//this.lblII.Visible = true;
S_Timer1.Start();

HeshanKit said...

works great.. but i can't understand some timer codes

Tharindu Edirisinghe said...

@HeshanKit - Sorry for that. I did it with a tight schedule and had no time to comment the source code much or follow proper coding standards :)

Anonymous said...

ok, thanks. This program is used full for me.

Eunice Cabigon said...

it helps me a lot:)

Post a Comment