數據結構-排序算法-希爾排序

//希爾插入排序
void shellInsertSort(int *a, int dataNum)
{
	int gap = dataNum / 2;
	int start = 0;
	while (gap >= 1)
	{
		while (start+gap<dataNum)
		{
			for (int i = start + gap; i < dataNum; i += gap)
			{
				int temp = a[i];
				int j = i - gap;
				while (j >= start && temp < a[j])
				{
					a[j + gap] = a[j];
					a[j] = temp;
					j -= gap;
				}
				a[j + gap] = temp;
			}
			start += 1;
		}
		gap /= 2;
		start = 0;
	}
}
相關文章
相關標籤/搜索