static void shell_sort(int[] unsorted, int len)
{
int group, i, j, temp;
for (group = len / 2; group > 0; group /= 2)
{
for (i = group; i < len; i++)
{
for (j = i - group; j >= 0; j -= group)
{
if (unsorted[j] > unsorted[j + group])
{
temp = unsorted[j];
unsorted[j] = unsorted[j + group];
unsorted[j + group] = temp;
}
}
}
}
}
static void Main(string[] args)
{
int[] x = { 6, 2, 4, 1, 5, 9 };
shell_sort(x, x.Length);
foreach (var item in x)
{
Console.WriteLine(item);
}
Console.ReadLine();
} |