Selection Sort algorithm using C#

In selection sort algorithm it takes smallest value from the array and move the value to the left.This process will continue until the complete array is sorted.

Algorithm


namespace SelectionSortAlgorithm
{
internal class Program
{
private static readonly int[] ArrayToBeSorted = new[] {5, 1, 0, 2};
private static void Main(string[] args)
{
int i;
for (i = 0; i < ArrayToBeSorted.Length - 1; i++)
{
int min = i;
int j;
for (j = i + 1; j < ArrayToBeSorted.Length; j++)
{
if (ArrayToBeSorted[j] < ArrayToBeSorted[min])
{
min = j;
}
}
int temp = ArrayToBeSorted[i];
ArrayToBeSorted[i] = ArrayToBeSorted[min];
ArrayToBeSorted[min] = temp;
}
int[] sortedResult = ArrayToBeSorted;
}
}
}

Enjoy coding…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s