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(0É17,&$
{}
O ///Q∧≤QGRQGHQ HTXLYDOHDO λ
creal(l)
SRV≤SRV≤QHVODSRVLFLyQGHOSXQWRGHLQWHUpV
{l
=λ ∧ pos=1}
{l =L1L2...Ln ∧ pos=i ∧ 1≤pos≤n }
suprime(l)
{l=L’1 L’2...L’n-1 ∧(L’1=L1...L’i-1= Li-1)∧
(L’i=Li+1...L’n-1= Ln)∧ pos=i }
{l =L1L2..Ln ∧ pos=i ∧ 1≤pos≤n+1 ∧ e=E }
inserta(l,e)
{l=L’1L’2...L’n+1∧ ( L’1=L1 ∧ .. ∧ L’i-1=Li-1 )
∧ L’i=E ∧ pos=i+1
{l = L1L2...Ln ∧ 1≤pos≤n }
e:=recupera(l)
{l = L1L2...Ln ∧ e=Lpos}
∧ (L’i+1=Li ∧ .. ∧ L’n+1=Ln)}
FRQWLQXD➠
FRQWLQXD➠
(VSHFLILFDFLyQGHO7$'/,67$
6(0É17,&$
{l=L1 L2...Ln ∧ 0≤n}
principio(l)
{l=L1L2...Ln ∧ pos=1}
{l=L1L2...Ln ∧ 0≤n}
b:=esvacial(l)
{b=(n=0)}
{l=L1L2...Ln ∧ 0≤n}
fin(l)
{l=L1L2...Ln ∧ pos=n+1}
{l=L1L2...Ln ∧ 0≤n}
b:=esfin(l)
{b=(pos=n+1)}
,PSOHPHQWDFLRQHVGHORVWLSRV
OLQHDOHV
•$VLJQDFLyQGLQiPLFDGHPHPRULDSXQWHURV
•,PSOHPHQWDFLRQHVGHOWLSR3LOD
•,PSOHPHQWDFLRQHVGHOWLSR&ROD
•,PSOHPHQWDFLRQHVGHOWLSR/LVWDFRQSXQWRGH
LQWHUpV
{l=L1L2...Ln ∧ 1≤pos≤n ∧ pos=i}
siguiente(l)
{ l=L1L2...Ln ∧ pos=i+1}
Descargar