#include <iostream>
using namespace std;
void Show(int* pList, int nCount)
{
for (int nIndex = 0; nIndex < nCount; nIndex++)
cout << pList[nIndex] << "\t";
cout << endl;
}
void Sort(int* pList,int nLen,int nIndex)
{
int nSave = pList[nIndex];
int nMove;
for (nMove = nIndex - nLen; nMove >= 0 && nSave < pList[nMove]; nMove -= nLen)
pList[nMove + nLen] = pList[nMove];
pList[nMove + nLen] = nSave;
}
void ShellSort(int* pList,int nCount)
{
for (int nLen = nCount / 2; nLen > 0; nLen /= 2)
for (int nIndex = nLen; nIndex < nCount; nIndex++)
Sort(pList, nLen, nIndex);
}
int main(int argc, char* argv[], char* enp[])
{
//int pList[] = {15,64,85,35,47,95,46,35,59,80};
//int pList[] = { -15,0,17,18,19,20,21,22,23,24 };
int pList[] = { 15,14,13,12,11,10,9,8,7,6 };
int nCount = sizeof(pList) / sizeof(int);
ShellSort(pList, nCount);
Show(pList, nCount);
getchar();
return 0;
}