Acasa Tehnologie Lista circulara dublu inlantuita: parcurgere

Lista circulara dublu inlantuita: parcurgere

by Dragos Schiopu

>Parcurgerea listei circulare dublu inlantuite inainte si inapoi.

program lcdi;
uses crt;
type nod=^ref;
ref=record
info:integer;
prec,urm:nod;
end;
var p,prim,ultim:nod;
n:integer;
procedure creare_lcdi;
begin
prim:=nil;
ultim:=nil;
write('Introd. info: ');readln(n);
while n<>0 do begin
new(p);
p^.info:=n;
if prim=nil then begin
p^.urm:=nil;
p^.prec:=nil;
ultim:=p;
prim:=p;
end
else begin
p^.urm:=nil;
p^.prec:=ultim;
ultim^.urm:=p;
ultim:=p;
end;
write('Introd. info: ');readln(n);
end;
end;
procedure afisare;
begin
p:=prim;
while p<>nil do
begin
write(p^.info,' ');
p:=p^.urm;
end;
end;
procedure parcurg_direct;
begin
writeln('Lista circulara dublu inlantuita parcursa direct:');
p:=prim;
while p<>nil do
begin
write(p^.info,' ');
p:=p^.urm;
end;
write(prim^.info);
end;
procedure parcurg_invers;
begin
writeln('Lista circulara dublu inlantuita parcursa invers:');
p:=ultim;
while ultim<>nil do
begin
write(ultim^.info,' ');
ultim:=ultim^.prec;
end;
write(p^.info);
end;
BEGIN
clrscr;
creare_lcdi;
afisare;writeln;
parcurg_direct;writeln;
parcurg_invers;
readln;
END.

s-ar putea sa-ti placa