40.

-

, -

.

() , -

, -

.

. -

, . -

, ,

.

:

- ;

- ;

- .

:

- ( );

- ;

- ;

- (-

);

- .

-

, ,

- , - .

-

:

 

type

PComp= ^Comp;

Comp= record

D:T;

pNext:PComp

end;

var

pBegin, pEnd, pCKey, pPreComp, pAux: PComp;

 

pBegin - , pEnd - ,

pCKey, pPreComp, pAux - .

,

, .

 

ͻͻͻͻ ͻͻ

*ĺĿ D1 D2 DN1 DNĺ*

ͼ ͺͺͺ ͺ ͼ

pBegin>*ĺ> *ĺ....>*ĺ> NIL < pEnd

ͼͼͼ ͼ

-

:

pCKey:=pBegin;

while (pCKey<>NIL) and (Key<>pCKey^.D) DO

pCKey:=pCKey^.pNext;

Key - , .

pKey

.

pCKey .

:

New(pAux);ͻ

pAux^.D:= DK1;ĺ*

ͼ

pCKey

ͻͻͻͻͻͻ

*ĺĿD1 KeyKK1DN ĺ*

ͼͺ ͺͺͺͼ

pBegin > *ĺ...> *ĺ> *ĺ...>NIL<pEnd

ͼͼͼͼ

ͻͻ

DK1ĺ*

ͺͼ

<pAux

ͼ

pAux^.pNext:=pCKey^.pNext;

pCKey^.pNext:=pAux;

ͻ

ĺ*

ͼ

pCKey

ͻͻͻͻͻͻ

*ĺĿD1 KeyKK1DN ĺ*

ͼͺ ͺͺͺͼ

pBegin > *ĺ...> * *ĺ...>NIL< pEnd

ͼͼͼͼ

^

ͻͻ

DK1ĺ-*

ĺͺͼ

>* < pAux

ͼ

:

 

pCKey:=pBegin;

while (pCKey<>NIL) and (Key<>pCKey^.D) do

begin

pPreComp:=pCKey;

pCKey:=pCKey^.pNext

end;

pCKey , -

pPreComp .

Key :

 

pPreComp^.pNext:=pCKey^.pNext;

pPreComppCKey

ͻͻ

* *

ͼͼ

ͻͻͻͻͻͻ ͻ

*ĺĿD1 KK1KeyKK2DN ĺ*

ͼͺ ͺͺͺ ͺͼ

pBegin > *ĺ...> *ĺĿ *ĺ> *ĺ...>NIL<pEnd

ͼͼ ͼͼͼ

^

. , ,

,

,

. . -

, - END.

 

Program LISTLINKED;

uses Crt;

type

Alfa= String[10];

PComp= ^Comp;

Comp= record

sD:Alfa;

pNext:PComp

end;

var

pBegin, pEnd, pAux, pCKey, pPreComp: PComp;

sC, sKey: Alfa;

bCond: Boolean;

Procedure CreateLL(var pBegin,pEnd: PComp; var sC: Alfa);

begin

New(pBegin);

pBegin^.pNext:=NIL;

pBegin^.sD:=sC;

pEnd:=pBegin

end;

Procedure AddLL(var pEnd: PComp; var sC: Alfa);

var pAux: PComp;

begin

New(pAux);

pAux^.pNext:=NIL;

pEnd^.pNext:=pAux;

pEnd:=pAux;

pEnd^.sD:=sC

end;

Procedure Find(var sKey: Alfa; var pBegin,pCKey,pPreComp: PComp;

var bCond: Boolean);

begin

pCKey:=pBegin;

while (pCKey <> NIL) and (sKey <> pCKey^.D) do

begin

pPreComp:=pCKey;

pCKey:=pCKey^.pNext

end;

if (pCKey = NIL) and (sKey <> pCKey^.sD) then bCond:=FALSE

else bCond:=TRUE

end;

Procedure InsComp(var sKey,sC: Alfa);

var pAux:PComp;

begin

Find(sKey,pBegin,pCKey,pPreComp,bCond);

New(pAux);

pAux^.sD:=sC;

pAux^.pNext:=pCKey^.pNext;

pCKey^.pNext:=pAux

end;

Procedure DelComp(var sKey: Alfa; var pBegin: PComp);

begin

Find(sKey,pBegin,pCKey,pPreComp,bCond);

pPreComp^.pNext:=pCKey^.pNext

end;

begin

ClrScr;

writeln(' ');

readln(sC);

CreateLL(pBegin,pEnd,sC);

repeat

writeln(' ');

readln(sC);

AddLL(pEnd,sC)

until sC='END';

writeln(' ***** *****');

pAux:=pBegin;

repeat

writeln(pAux^.sD);

pAux:=pAux^.pNext;

until pAux=NIL;

writeln;

writeln(' ');

readln(sKey);

writeln(' ');

readln(sC);

InsComp(sKey,sC);

writeln;

writeln(' ');

readln(sKey);

DelComp(sKey,pBegin);

writeln;

writeln(' ***** *****');

pAux:=pBegin;

repeat

writeln(pAux^.sD);

pAux:=pAux^.pNext;

until pAux=NIL

end.

, , ,