![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
static void ShellPass(int[] array, int d)
{
for (int i = d; i < array.Length; i++)
{
if (array[i] < array[i - d])
{
int tmp = array[i];
int j = 0;
for (j = i - d; j >=0 && tmp < array[j]; j -= d)
{
array[j + d] = array[j];
}
array[j + d] = tmp;
}
foreach (int a in array)
{
Console.Write(a + " ");
}
Console.Write(Environment.NewLine);
}
}
static void ShellSort(int[] array)
{
int increment = array.Length/2;
for (int k = increment; k > 0; k = k / 2)
{
ShellPass(array, k);
}
}
static void Main(string[] args)
{
int[] a = new int[] { 6,2,5,3,1,4,7 };;
ShellSort(a);
}
{
for (int i = d; i < array.Length; i++)
{
if (array[i] < array[i - d])
{
int tmp = array[i];
int j = 0;
for (j = i - d; j >=0 && tmp < array[j]; j -= d)
{
array[j + d] = array[j];
}
array[j + d] = tmp;
}
foreach (int a in array)
{
Console.Write(a + " ");
}
Console.Write(Environment.NewLine);
}
}
static void ShellSort(int[] array)
{
int increment = array.Length/2;
for (int k = increment; k > 0; k = k / 2)
{
ShellPass(array, k);
}
}
static void Main(string[] args)
{
int[] a = new int[] { 6,2,5,3,1,4,7 };;
ShellSort(a);
}