. , , ,

,,,

,

1. ŽŽŸ Ž Ž ŽƒŒŒˆŽˆž ˆŠ 10 Š ˜ŠŽ N57

ŒŽ ƒŸ Ž Œ "ŽˆŽŠˆ".

2. ŽŽŠ ˆ.

  ä , á¥à é¨ ç¨á  ⨯  longint, à á¯¥ë¥ ¢ ¯à¨¢ì

¯à瘟. ॡã¥âáï à á¯¨âì í⨠ç¨á  ¯ ¢à áâ ¨î, ¨á¯ìãï ¥ ¡¥¥

40 ª¨¡ â ¯¥à â¨¢ ¯ ï⨠¨ ¨áª¢£ ¯àáâà á⢠ ¥ ¡¥¥ ç¥ ¢ ¢ 

à   ¡ìè¥ ¨áå£ ä  .

3. ƒŽˆŒ (¥â à¥è¥¨ï).

 ç   ¨áåë ä  à ¡¨¢ ¥âáï   ªã᪨ ¯ 10000 ç¨á¥, ª ë ªãáª

áàâ¨àã¥âáï ¢ ¯ ï⨠¨  ¯¨á뢠¥âáï ¢ ¨ ¨ ¢ãå ¢à¥¥ëå ä ¢, ¯à¨ç¥

â ª, çâ ª¨ç¥á⢠ªã᪢ ¢ íâ¨å ä  å â¨ç ¥âáï ¥ ¡¥¥ ç¥   1( ¥¥ -

¯¥à¢ ç ì ï áàâ¨à¢ª ).

 â¥, ¥áªìª à  ¢ë¯ï¥âáï ¯¥à æ¨ï "᪥¨¢ ¨¥"( ¢ë¯¥¨¥

¯¥à æ¨¨ "᪥¨¢ ¨¥" ë ¡ã¥ ¥ë¢ âì "è £"), â.¥ ¢  ¨áåëå

ä  , ¢ ªâàëå  å¨¨áì âáàâ¨à¢ ë¥ ªã᪨ ª¯¨àãîâáï ¢ ¢  à㣨å

ä  , ¯à¨ íâ ¨ ¢ãå ªã᪢,  åïé¨åáï ¢ à ëå ä  å ¨ ¨¥îé¨å

¨ ª¢ë¥ ¥à  á ¥âáï ¨ âáàâ¨à¢ ë ªãáª. ââ ªãáª

 ¯¨á뢠¥âáï ¢ ¯¥à¢ë ¢ëå ä  ¥á¨ ¨áåë¥ ªã᪨ ¨¥¨ ¥ç¥âë¥ ¥à 

¨ ¢ ¢âà, ¥á¨ ¨áåë¥ ªã᪨ ¨¥¨ ç¥âë¥ ¥à .

4. ŸŸ ˆˆŠˆŸ ŽƒŒŒ.

à¨  ¯¨á ¨¨ ¯à£à ë ¨á¯ì¢  áì áॠ Borland Pascal 7.0 ¨

¢áâà¥ë ª¯¨ïâà.

ï ãáªà¥£ ¡¥  á ¨áª ¯à¨¥ïáï ¡ª¢ë ¢¢-¢ë¢, â.¥

¨äà æ¨ï ç¨â ¥âáï ¨  ¯¨á뢠¥âáï æ¥ë¨ ª áâ¥à ¨. ï áãé¥á⢥¨ï íâ£

á¯á¡  ¢¢ -¢ë¢  ¡ë  ¯¨á  ãì(Files), á ¯éìî ªâ࣠¢¢-¢ë¢

¢¥è¥ ¥ â¨ç ¥âáï â ¡ëç£.

奠 ¯à£à ë ¯à¥¥ì ¯àáâ : á ç   ¢ë¯ï¥âáï ¯¥à¢ çì ï

áàâ¨à¢ª (¯àæ¥ãà  firstsort),  â¥ ¢ë뢠¥ ᪥¨¢ ¨¥(¯àæ¥ãà 

ftrans(in1, in2, out1, out2: workfile);), £¥ ¯ àë ä ¢ ¢á¥ ¢à¥ï ¥ïîâáï ¨

¯á¥ ª £  ¯ã᪠ ¯àæ¥ãàë ¯à¢¥àï¥âáï ãᢨ¥ ¢ëå .

àæ¥ãà  ftrans âªà뢠¥â ¢á¥ ä ë,  â¥ ¢ë¯ï¥â ¥áªìª à 

¯àæ¥ãàã ᨢ  £ ªã᪠(onestep) ¨  ªà뢠¥â ä ë.

5. ŠŽŒŒˆŽ Š ŽƒŒŒ.

{Œãì Files.

¥áì ¯¥à¥¯¨á ë ¢á¥ ¯àæ¥ãàë ¨ äãªæ¨¨ ¥¡å¨ë¥ ï à ¡âë á ä  ¨,

à ¡â î騥 á ¡ª ¨.  ¡â  á ¨¨ áãé¥áâ¢ï¥âáï â ª¥ ª ª ¨ á

¡ëçë¨ ¯àæ¥ãà ¨ ãï System.}

unit Files;

interface

const typesize=4;

const bufsize = 2048;

type using=longint;

type buffer = array[1..bufsize] of using;

type pbuffer = ^buffer;

type filemode = (fread, fwrite, closed);

type tfile = record

buf: pbuffer;

mode: filemode;

f: file;

count, leng: integer;

end;

procedure fAssign(var w: tfile; name: string);

procedure fReWrite(var w: tfile);

procedure fReset(var w: tfile);

procedure fPut(var w: tfile; d: using);

procedure fGet(var w: tfile; var d: using);

procedure fClose(var w: tfile);

function fEof(var w: tfile): boolean;

implementation

procedure fAssign(var w: tfile; name: string);

begin

Assign(w.f, name);

w.mode:=closed;

end;

procedure fReWrite(var w: tfile);

begin

if w.mode=closed then

begin

ReWrite(w.f, typesize);

new(w.buf);

w.count:=0;

w.leng:=0;

w.mode:=fwrite;

end;

end;

procedure fReset(var w: tfile);

begin

if w.mode=closed then

begin

Reset(w.f, typesize);

new(w.buf);

BlockRead(w.f, w.buf^, bufsize, w.leng);

w.count:=1;

w.mode:=fread;

end;

end;

procedure fPut(var w: tfile; d: using);

begin

if w.mode=fwrite then

begin

w.count:=w.count+1;

w.buf^[w.count]:=d;

if w.count=bufsize then

begin

BlockWrite(w.f, w.buf^, w.count);

w.count:=0;

end;

end;

end;

procedure fGet(var w: tfile; var d: using);

begin

if (w.mode=fread) then

begin

d:=w.buf^[w.count];

if w.leng=w.count then

begin

BlockRead(w.f, w.buf^, bufsize, w.leng);

w.count:=1;

end else w.count:=w.count+1;

end;

end;

procedure fClose(var w: tfile);

begin

if w.mode=fwrite then BlockWrite(w.f, w.buf^, w.count);

dispose(w.buf);

w.mode:=closed;

Close(w.f);

end;

function fEof(var w: tfile): boolean;

begin

if (w.mode=fread) and (w.leng=0) then fEof:=true

else fEof:=false;

end;

begin

end.

{ª¥æ files.pas}

{----------------------------------------------------------------------------}

{  sort.pas - áàâ¨à¢ª  ¢ ¯ ïâ¨.}

var k: integer;

function SwapTops(no: integer): integer;

var t: longint;

begin

if (memo^[2*no+1]>memo^[2*no]) then

begin

t:=memo^[no];

memo^[no]:=memo^[2*no+1];

memo^[2*no+1]:=t;

SwapTops:=2*no+1;

end else

begin

t:=memo^[no];

memo^[no]:=memo^[2*no];

memo^[2*no]:=t;

SwapTops:=2*no;

end;

end;

procedure SwapHalf(no: integer);

var t: longint;

begin

if memo^[no]

begin

t:=memo^[no];

memo^[no]:=memo^[2*no];

memo^[2*no]:=t;

end;

end;

function Reg(no: integer): boolean;

begin

if (2*no)>k then Reg:=true else

if (2*no+1)>k then

begin

SwapHalf(no);

Reg:=true;

end else

if (memo^[2*no]<=memo^[no]) and (memo^[2*no+1]<=memo^[no]) then Reg:=true

else Reg:=false;

end;

procedure HalfReg(no: integer);

var next: integer;

begin

next:=no;

while (not Reg(next)) do next:=SwapTops(next);

end;

procedure RegTree;

var i: integer;

begin

for i:=k downto 1 do HalfReg(i);

end;

procedure SwapLeaves(l1, l2: integer);

var t: longint;

begin

t:=memo^[l1];

memo^[l1]:=memo^[l2];

memo^[l2]:=t;

end;

procedure SortMemo(len: integer);

begin

k:=len;

RegTree;

for k:=len-1 downto 1 do

begin

SwapLeaves(1, k+1);

HalfReg(1);

end;

end;

{ª¥æ sort.pas}

{----------------------------------------------------------------------------}

{Žá¢ ï ¯£à  }

uses Dos, Files{ªî票¥ ãï, áãé¥áâ¢ïî饣 ¢¢-¢ë¢.};

const memlen=10000;{ ¥à ¯ ïâ¨, à à¥è¥ ï ¨á¯ì¢ ¨ï}

type tmemo = array[0 .. memlen] of longint;

type pmemo = ^ tmemo;{¨¯-㪠 â¥ì   ᢠ áᨢ, ¨á¯ìã¥ë

¯à£à }

var memo : pmemo;

{$I sort.pas} {ªî票¥ ä  , á¥à é¥£ ¯àæ¥ãàã áàâ¨à¢ª¨

 áᨢ    ¢à¥ï n*(log n), ¥ ¨á¯ìãï ¯¨â¥ì ¯ ïâ¨(áàâ¨à¢ª 

¥à¥¢).}

type workfile = record

main{ᢠä },

inf{ä , á¥à é¨ ¨ë âáàâ¨à¢ ëå ªã᪢}: tfile;

end;{tfile - ⨯, ¯à¥¥¥ë ¢ unit Files, ªâàë  ¥ï¥â ä ¢ë¥ â¨¯ë}

var

t1, t2, t3, t4, dest, seur: workfile;

{¢à¥¥ë¥ ä ë} {¢å ¨ ¢ëå ä }

{ˆ¨æ¨ ¨ æ¨ï}

procedure Init;

var tmp: string;

begin

tmp:=getenv('TEMP');

fAssign(t1.main, tmp+'~fsort-1.tmp');

fAssign(t2.main, tmp+'~fsort-2.tmp');

fAssign(t3.main, tmp+'~fsort-3.tmp');

fAssign(t4.main, tmp+'~fsort-4.tmp');

fAssign(t1.inf, tmp+'~finf-1.tmp');

fAssign(t2.inf, tmp+'~finf-2.tmp');

fAssign(t3.inf, tmp+'~finf-3.tmp');

fAssign(t4.inf, tmp+'~finf-4.tmp');

fAssign(seur.main,ParamStr(1));

fAssign(dest.main,ParamStr(2));

end;

{¥à¢ ç ì ï áàâ¨à¢ª }

procedure firstsort(var inp, out1, out2: workfile);

var i, k: longint;

begin

fReset(inp.main);

fRewrite(out1.main);

fRewrite(out2.main);

fRewrite(out1.inf);

fRewrite(out2.inf);

new(memo);

repeat

for i:=1 to memlen do

if fEof(inp.main) then

begin

i:=i-1;

break

end else fGet(inp.main, memo^[i]);

k:=i;

sortmemo(k);

for i:=1 to k do fPut(out1.main, memo^[i]);

fPut(out1.inf, k);

if k=memlen then

begin

for i:=1 to memlen do

if fEof(inp.main) then

begin

i:=i-1;

break;

end

else fGet(inp.main, memo^[i]);

k:=i;

sortmemo(k);

for i:=1 to k do fPut(out2.main, memo^[i]);

fPut(out2.inf, k);

end;

until fEof(inp.main);

dispose(memo);

fClose(inp.main);

fClose(out1.main);

fClose(out2.main);

fClose(out1.inf);

fClose(out2.inf);

end;

{àæ¥ãà , ª¯¨àãîé ï   ¥ ª¨ç¥á⢠í-⢠¨ £ ä   ¢ àã£.

ˆá¯ìã¥âáï ¯à¨ á¨¢ ¨¨ ï ª¯¨à¢ ¨ï áâ ¢è¥áï ç á⨠ªã᪠(¥á¨ àã£

ªã᪠¨ááïª).}

procedure Copy(var inp, out: workfile; c0: longint);

var

c, n: longint;

Done: boolean;

begin

for c:=c0 downto 1 do

begin

fGet(inp.main, n);

fPut(out.main, n);

end;

end;

{¨¢ ¥â ¢  ç¥à¥ëå ªã᪠ ¨ ä ¢ in1 ¨ in2 ¨  ¯¨á뢠¥â ¢ out.}

procedure onestep(var in1, in2, out: workfile; c01, c02: longint);

var n1, n2, c1, c2, c: longint;

Done: boolean;

begin

Done:=false;

c1:=c01-1;

c2:=c02-1;

c:=0;

fGet(in1.main, n1);

fGet(in2.main, n2);

repeat

if n1

begin

fPut(out.main, n1);

c:=c+1;

if c1=0 then

begin

fPut(out.main, n2);

c:=c+1;

Copy(in2, out, c2);

c:=c+c2;

Done:=true;

end else

begin

fGet(in1.main, n1);

c1:=c1-1;

end;

end else

begin

fPut(out.main, n2);

c:=c+1;

if c2=0 then

begin

fPut(out.main, n1);

c:=c+1;

Copy(in1, out, c1);

c:=c+c1;

Done:=true;

end else

begin

fGet(in2.main, n2);

c2:=c2-1;

end;

end;

until Done;

end;

{àæ¥ãà  áãé¥áâ¢ï¥â ¨ è £(â.¥. ª¯¨àã¥â ä ë in1 ¨ in2 ¢ out1 ¨ out2,

¯à¨ íâ ᪥¨¢ ï ªã᪨)}

procedure ftrans(var in1,in2,out1,out2: workfile);

var c1, c2, c: longint;

begin

fReset(in1.main);

fReset(in2.main);

fReset(in1.inf);

fReset(in2.inf);

fRewrite(out1.main);

fRewrite(out2.main);

fRewrite(out1.inf);

fRewrite(out2.inf);

while (not fEof(in1.inf)) and (not fEof(in2.inf)) do

begin

fGet(in1.inf, c1);

fGet(in2.inf, c2);

onestep(in1, in2, out1, c1, c2);

c:=c1+c2;

fPut(out1.inf, c);

if (not fEof(in1.inf)) and (not fEof(in2.inf)) then

begin

fGet(in1.inf, c1);

fGet(in2.inf, c2);

onestep(in1, in2, out2, c1, c2);

c:=c1+c2;

fPut(out2.inf, c);

end;

end;

if fEof(in1.inf) xor fEof(in2.inf) then

if fEof(in1.inf) then

begin

fGet(in2.inf, c2);

Copy(in2, out2, c2);

fPut(out2.inf, c2);

end else

if fEof(in2.inf) then

begin

fGet(in1.inf, c1);

Copy(in1, out2, c1);

fPut(out2.inf, c1);

end;

fClose(in1.main);

fClose(in2.main);

fClose(in1.inf);

fClose(in2.inf);

fClose(out1.main);

fClose(out2.main);

fClose(out1.inf);

fClose(out2.inf);

end;

{Š¯¨à¢ ¨¥ ä   f1 ¢ f2.(ˆá¯ìã¥âáï ¯à¨  ¢¥à襨¨ à ¡âë ï

ª¯¨à¢ ¨ï ª¥ç£ ä   ¨ ¢à¥¥ ¨à¥ªâਨ ¢ 㪠 ãî).}

procedure FCopy(f1, f2: tfile);

var t: longint;

begin

write('ª¯¨à¢ ¨¥');

fRewrite(f2);

fReset(f1);

while (not fEof(f1)) do

begin

fGet(f1, t);

fPut(f2, t);

end;

fClose(f1);

fClose(f2);

end;

{à¨¨ ¥â  ç¥¨¥ True, ¥á¨ ä  âáàâ¨à¢  ¨ ¡ìè¥ ¥   ᪥¨¢ âì.

(ᢨ¥ ¢ëå )}

function Fin: boolean;

begin

fReset(t2.main);

fReset(t4.main);

if fEof(t2.main) then

begin

Fin:=true;

FCopy(t1.main, dest.main);

end else

if fEof(t4.main) then

begin

Fin:=true;

FCopy(t3.main, dest.main);

end else Fin:=false;

fClose(t2.main);

fClose(t4.main);

end;

begin

writeln;

if ParamCount<2 then

begin

writeln('¨èª   ¯ à ¥âà¢.');

Exit;

end;

write('ˆ¨æ¨ ¨ æ¨ï...');

Init;

writeln('£â¢');

write('¥à¢ ç ì ï áàâ¨à¢ª ...');

firstsort(seur, t1, t2);

writeln('£â¢');

ReWrite(dest.main.f);

Close(dest.main.f);

writeln('ª¥¨¢ ¨¥:');

repeat

ftrans(t1, t2, t3, t4);

writeln('è £');

if (not Fin) then

begin

ftrans(t3, t4, t1, t2);

writeln('è £');

end;

until Fin;

writeln('£â¢');

end.

{----------------------------------------------------------------------------}

6. ˜ŸŸ ˆˆŠˆŸ.

ï ªà४â à ¡âë ¯à£à ë ¥¡å¨ ª¯ìîâ¥à AT286, 40K ᢡ

conventional ¯ ïâ¨, ¯¥à æ¨ ï á¨á⥠ MS-DOS 3.0 ¨¨ ¡¥¥ ¯ïï ¢¥àá¨ï.

ë ¢¥àᨨ ¯à£à ë, ¨á¯ìãî騥 ¥ìè¥ ¯ ïâ¨, ¯àæ¥ááàë á ¡¥¥ 286 ¨

â.. à£à   ¨á¯ìã¥â ¥áâ   ¨áª¥ ¢¢¥ ¡ì襥 ¨áå£ ä  (¥

áç¨â ïï á  ä ).

7. ŠŽŽŽ ŽœŽŸ.

à¨  ¯ã᪥ ¯à£à ë ¡ï â¥ì   ¡ëâì ¯à¥¥¥  ¯¥à¥¥ ï áà¥ë TEMP!

à â  ¯ã᪠ ¯à£à ë:

f_sort[.exe] <¢å ä > <¢ëå ä >

à£à   ¥   ¥â ¨ ª ª¨å ¢¯àá¢, çâ á¨ì ã¯àé ¥â à ¡âã á ¥.

¥ãìâ â à ¡âë ¯¢¥à¨âì á ¯éìî ¯à¨ £ ¥ ã⨨âë f_check,

á âì áãç ë ¨áåë ä  - á ¯àéìî f_make.

à¨ç¨ ¨ 訡ª £ãâ áã¨âì ¥ á⢥âá⢨¥ á¨áâ¥ë âॡ¢ ¨ï,

¨¥ë ¢ ¯. 6, ¥áâ âç¥ ¥áâ   ¨áª¥, à ¥à(¢ ¡ â å) ¨áå£

ä   ¥ ªà â¥ 4.

  âç¥â¥ ¯¨á뢠¥âáï á  ï í䥪⨢ ï ¢¥àá¨ï íâ ¯à£à ë,

áãé¥áâ¢ãîâ ¢¥àᨨ, ¥ ¨á¯ìãî騥 ¢¢-¢ë¢ ¡ª ¨, âॡãî騥 ¥ìè¥

à¥áãàᢠá¨áâ¥ë.

8. Žˆˆ Ž.

à£à   â¥áâ¨à¢  áì ¥ªâ â,   ¢å¥ ¨á¯ì¢ ¨áì, ¢ á¢,

ä ë ¨ áãç ëå ç¨á¥ à ¨ç ¨ë.   ¢ëå¥ ¡ë¨ ¯ãç¥ë ä ë â¥

¨ë, ¥ á¥à é¨¥ 訡ª, â.¥. ç¨á  ¢ íâå ä  å ª  ¨áì ¢ ¯à瘟

¥ áâࣣ ¢à áâ ¨ï. ¥à¨¥ íâ¨å ä ¢ ¯áâìî ᢯  á

à ãìâ â ¨ à ¡âë àã£¨å ¯à£à  áàâ¨à¢ª¨   â¥å ¥ ¢åëå ä  å, çâ

á¨ì ᨠ¥â ¢¥àïâáâì ¨ä¥ªâ¢ ¯à£à ë.

à¨ â¥áâ¨à¢ ¨¨ ¨á¯ì¢ ¨áì ¯¥à æ¨ë¥ á¨áâ¥ë MS-DOS 6.22,

Windows`95, ª¯ìîâ¥àë PC AT 486DX4-100, 486SX-25, à ¡â î騥 á ª ìë

¢¨ç¥áâ¥à, à¡ç¨¥ áâ æ¨¨ 486DX-40, 386SX, à ¡â î騥 ¢ á¥â¨ Novell.

¥ãìâ âë â¥áâ¨à¢ ¨ï(  ä ¥ à ¥à 4M)  ¥á¥ë ¢ â ¡¨æã:

ª¯ìîâ¥à à ¡â  ¢ á¥â¨ ¢à¥ï à ¡âë

486DX4-100 ¥â 3 ¨.

486SX-25 ¥â 7 ¨.

486DX-40  

386SX  

1. &#129;&#381;&#144;&#381;&#144;&#141;&#376; &#144;&#129;&#381; &#143;&#381; &#143;&#144;&#381;&#402;&#144;&#338;&#338;&#710;&#144;&#381;&#141;&#710;&#382; &#141;&#710;&#352; 10 &#352; &#732;&#352;&#381; N57 &#338;&#14

 

 

 

! , , , .
. , :