.


:




:

































 

 

 

 


. 6

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 ----* L=====- ===== ===== ===== ===== L=====-pBegin L--> *-----> *---....-> *-----> NIL <-- pEnd L=====- L=====- L=====- L=====- - : pCKey:=pBegin; while (pCKey<>NIL) and (Key<>pCKey^.D) DO pCKey:=pCKey^.pNext; Key - , . pKey . pCKey . : New(pAux); === pAux^.D:= DK1; ----* L===- pCKey === === === === === === *--- D1 Key KK1 DN ----* L===- === === === === L===-pBegin L-> *--...-> *-----> *--...->NIL<-- pEnd L===- L===- L===- L===- === === DK1 ----* === L===- <-- pAux L===- pAux^.pNext:=pCKey^.pNext; pCKey^.pNext:=pAux; === ----* L===- pCKey === === === === === === *--- D1 Key KK1 DN ----* L===- === === === === L===-pBegin L-> *--...-> * *--...->NIL<-- pEnd L===- L===- L===- L===- ^ === === DK1 ----* L----------=== L===- L------------------->-* <-- pAux L===- : pCKey:=pBegin; while (pCKey<>NIL) and (Key<>pCKey^.D) do begin pPreComp:=pCKey; pCKey:=pCKey^.pNext end; pCKey , - pPreComp . Key : pPreComp^.pNext:=pCKey^.pNext; pPreComp pCKey === === * * L===- L===- === === === === === === === *--- D1 KK1 Key KK2 DN ----* L===- === === === === === L===-pBegin L-> *--...-> *-- *----> *--...->NIL<-- pEnd L===- L===- L===- L===- L===- ^ L--------------- . , , , , . . - , - 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.

1 | 2 | 3 | 4 | 5 | 6




<== | ==>
| .
:


: 2016-12-31; !; : 279 |


:

:

,
==> ...

1952 - | 1793 -


© 2015-2024 lektsii.org - -

: 0.013 .