shell排序

typedef bool (*Func)(int a, int b); void ShellSort(vector<int>& vec, Func fun) { int iSize = vec.size(); int iStep = iSize; int iCnt = 0; int iTmp = 0; do { iStep = iStep / 3 + 1; for (int i = iStep; i < iSize; i++) { if (!(*fun)(vec[i - iStep], vec[i])) { iTmp = vec[i]; iCnt = i - iStep; do { vec[iCnt + iStep] = vec[iCnt]; iCnt -= iStep; } while (iCnt >= 0 && !(*fun)(vec[iCnt], iTmp)); vec[iCnt + iStep] = iTmp; } } } while (iStep > 1); } 

 

你可能感兴趣的:(shell排序)