program shell_sort; uses crt; type tlist=^treclist; treclist=record inf:integer; next:tlist; prev:tlist end; var genfirst: tlist; procedure create_list(var first:tlist; inp:string); var p:tlist; f:text; begin assign(f,inp); reset(f); new(p); first:=p; while not eof(f) do begin new(p^.next); p^.next^.prev:=p; p:=p^.next; read(f,p^.inf); p^.next:=nil; end; end; procedure output_list(first:tlist; out:string; q:boolean); var p:tlist; f:text; begin assign(f,out); if not q then rewrite(f) else begin append(f); writeln(f) end; p:=first; while p^.next<>nil do begin p:=p^.next; write(f,p^.inf,' ') end; close(f) end; procedure shellsort(first: tlist); var p,q:tlist; i,h,temp:integer; b:boolean; begin clrscr; h:=0; p:=first; while p^.next<>nil do begin p:=p^.next; inc(h) end; if h mod 2 = 0 then b:=true; h:=(h+1) div 2; while h>1 do begin writeln(h); p:=first; q:=p^.next; p:=q; for i:=1 to h-1 do p:=p^.next; while p<>nil do begin if q^.inf>p^.inf then begin temp:=q^.inf; q^.inf:=p^.inf; p^.inf:=temp end; q:=q^.next; p:=p^.next end; h:=(h+1) div 2; end; end; begin create_list(genfirst,'input.inp'); output_list(genfirst,'output.out',false); shellsort(genfirst); output_list(genfirst,'output.out',true) end.