250
>Operatii in coada: initializare, adaugare, parcurgere, eliminare.
{operatii in coada: initializare, adaugare, parcurgere, eliminare}
type coada=array[1..100] of integer;
var c:coada;
vf,sf,n,i:integer;
c_plina,c_vida:boolean;
opt:char;
procedure initializare;
var i:integer;
begin
write('numarul maxim de elemente al cozii=');readln(n);
for i:=1 to n do c[i]:=0;
vf:=1;
sf:=1;
end;
procedure adaugare;
var e:integer;
begin
write('elementul care se adauga=');
readln(e);
if vf=sf mod n+1 then c_plina:=true
else c_plina:=false;
if c_plina then
begin
writeln('depasire coada');
readln;
end
else
begin
c[sf]:=e;
sf:=sf mod n+1;
end;
end;
procedure parcurg;
var i:integer;
begin
if vf=sf then c_vida:=true
else c_vida:=false;
if c_vida then writeln('coada vida')
else
begin
writeln('stiva este:');
i:=vf;
while i<>sf do
begin
write(c[i]:5);
i:=i mod n+1;
end;
readln;
end;
end;
procedure eliminare;
var e:integer;
begin
if vf=sf then c_vida:=true
else c_vida:=false;
if c_vida then
begin
writeln('coada vida');
vf:=1;
sf:=1;
readln;
end
else
begin
e:=c[vf];
vf:=vf mod n+1;
end;
writeln('s-a eliminat elementul ',e);
end;
BEGIN
initializare;
write('adaugi element ? ');readln(opt);
repeat
adaugare;
write('adaugi element ?');readln(opt);
until (opt<>'d');
parcurg;
writeln('se va elimina un element din stiva');
eliminare;
parcurg;
END.
{PascalZone.uv.ro}