Shell排序的实现,注意dist=(dist+1)/2 是不断变化的距离,初始时是(N+1)/2,注意这个公式但dist为1时,dist之后永远为1.
输出:
make -f "Makefile" CFG=Debug
mingw32-make: Nothing to be done for `all'.
Debug/ShellSort20091103.exe
Befor Shell Sort: 2 3 1 4 5 7 4 9 0 2
dist-5 Shell Sort: 2 3 1 0 2 7 4 9 4 5
dist-3 Shell Sort: 0 2 1 2 3 4 4 9 7 5
dist-2 Shell Sort: 0 2 1 2 3 4 4 5 7 9
dist-1 Shell Sort: 0 1 2 2 3 4 4 5 7 9
After Shell Sort: 0 1 2 2 3 4 4 5 7 9
Befor Shell Sort: 12 43 12 46 57 72 40 90 20 11
dist-5 Shell Sort: 12 40 12 20 11 72 43 90 46 57
dist-3 Shell Sort: 12 11 12 20 40 46 43 90 72 57
dist-2 Shell Sort: 12 11 12 20 40 46 43 57 72 90
dist-1 Shell Sort: 11 12 12 20 40 43 46 57 72 90
After Shell Sort: 11 12 12 20 40 43 46 57 72 90