using System;
using System.Collections.Generic;
using System.Text;
namespace SortAlgorithms
{
class ShellSorter
{
public void Sort(int[] arr)
{
int inc;
for (inc = 1; inc <= arr.Length / 9; inc = 3 * inc + 1) ;
for (; inc > 0; inc /= 3)
{
for (int i = inc + 1; i <= arr.Length; i += inc)
{
int t = arr[i - 1];
int j = i;
while ((j > inc) && (arr[j - inc - 1]) > t)
{
arr[j-1] = arr[j-inc-1];
j -= inc;
}
arr[j - 1] = t;
}
}
}
static void Main(string[] args)
{
int[] arry = new int[] { 1, 5, 3, 6, 3, 34 };
ShellSorter s = new ShellSorter();
s.Sort(arry);
foreach (int m in arry)
{
Console.WriteLine("{0}", m);
}
Console.ReadLine();
}
}
}