procedure ShellSort(var AA: Array of Integer); var i, j, x, nTmp: Integer; begin x := 1; nTmp := High(AA) div 9; while (x <= nTmp) do x := (x * 3) + 1; while (x > 0) do begin for i := x to High(AA) do begin nTmp := AA[i]; j := i; while (j >= x) and (nTmp < AA[j - x]) do begin AA[j] := AA[j - x]; Dec(j, x); end; AA[j] := nTmp; end; x := x div 3; end; end;