C# Code to implement Insertion Sort

Kundnani.Rt
Posted by Kundnani.Rt under C# category on | Points: 40 | Views : 1454
static void InsertionSort(IComparable[] array)
{
int i, j;

for (i = 1; i < array.Length; i++)
{
IComparable value = array[i];
j = i - 1;
while ((j >= 0) && (array[j].CompareTo(value) > 0))
{
array[j + 1] = array[j];
j=j-1;
}
array[j + 1] = value;
}
}

Comments or Responses

Login to post response