C# Code to implement Selection Sort

Kundnani.Rt
Posted by Kundnani.Rt under C# category on | Points: 40 | Views : 1836
Selection Sort in C#:

static void SelectionSort(IComparable[] array)
{

int i, j;
int min;
IComparable temp;

for (i = 0; i < array.Length - 1; i++)
{
min = i;
for (j = i + 1; j < array.Length; j++)
{
if (array[j].CompareTo( array[min])<0)
min = j;
}
temp = array[i];
array[i] = array[min];
array[min] = temp;
}

for (i = 0; i < array.Length; i++)
Console.Write(array[i] + "\t");
}

Comments or Responses

Login to post response