どーでもいいけどshellsortのgapは
h := 1;
while h < n do
 h := h * 3 + 1;

while h > 0 do
begin
 h := h div 3;
が効率的。