Acasa Tehnologie Lista circulara simplu inlantuita: creare, parcurgere, stergere

Lista circulara simplu inlantuita: creare, parcurgere, stergere

by Dragos Schiopu

Lista circulara simplu inlantuita

>Operatii lista circulara simplu inlantuita: creare, parcurgere, stergere.

{operatii lista circulara simplu inlantuita: creare, parcurgere, stergere}
program oplcsi;
uses crt;
type nod=^ref;
ref=record
info:integer;
urm:nod;
end;
var p,q,prim,ultim:nod;
a,n:integer;
ch:char;
procedure creare_lc;
begin
write(' Introdu informatia nodului : ' );
readln(n);
prim:=nil;
ultim:=nil;
while n<>0 do
begin
new(p);
p^.info:=n;
if prim=nil then
begin
prim:=p;
ultim:=p;
p^.urm:=nil;
end
else
begin
p^.urm:=nil;
ultim^.urm:=p;
ultim:=p;
end;
write(' Introdu informatia nodului : ' );
readln(n);
end;
end;
procedure parcurgere;
begin
p:=prim;
while p<>nil do
begin
write(p^.info,' ');
p:=p^.urm;
end;
write(prim^.info);
end;
procedure stergere;
begin
writeln;
write(' Valoarea de sters : ');
readln(a);
p:=prim;
if p^.info=a then
begin
p:=prim^.urm;
dispose(prim);
prim:=p;
end
else
begin
while p^.urm^.info<>a do p:=p^.urm;
q:=p^.urm;
p^.urm:=q^.urm;
dispose(q);
end;
writeln(' Noua lista este : ');
end;
BEGIN
clrscr;
creare_lc;writeln;
writeln(' Lista circulara este : ');
parcurgere;
repeat
stergere;
parcurgere;writeln;
writeln(' Mai stergi ?');
readln(ch);
until (ch='n') or (ch='N');
END.

s-ar putea sa-ti placa

0 comentarii

muntean sorin 07-03-2012 - 20:21

A fost ok