public int[] InsertSortGap(int[] list, int gap)
{
int m_lenth = list.Length;
int m_sortNum;
for (int i = gap; i < m_lenth; i += gap)//每次取一个数,gap:希尔排序分段
{
for (int s = i - gap; s >= 0; s -= gap)//插入有序区
{
if (list[s + gap] < list[s])
{
m_sortNum = list[s + gap];
list[s + gap] = list[s];
list[s] = m_sortNum;
}
}
}
return list;
}
public int[] ShellSort(int[] list)
{
int d = list.Length / 2;
while (d >= 1)
{
InsertSortGap(list, d);
d /= 2;
}
return list;
}
ShellSort C#
于 2022-03-07 13:49:52 首次发布