C# Code to implement Shell Sort

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

increment = array.Length / 2;
while (increment > 0)
{
for (i = 0; i < array.Length; i++)
{
j = i;
temp = array[i];
while ((j >= increment) && (array[j - increment].CompareTo( temp)>0))
{
array[j] = array[j - increment];
j = j - increment;
}
array[j] = temp;
}
if (increment == 2)
increment = 1;
else
increment = increment * 5 / 11;

}

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

Comments or Responses

Login to post response