Работа с очередью: каждая операция создание, удаление, добавление,показ элементов очереди разделены на отдельные процедуры — Pascal(Паскаль)

uses crt;
type next=^rec;
 rec=record
 inf:longint;
 link:next;
 end;
var
 p,p1,p2,first,last:next;
 vq:longint;
 vxod:boolean;
 c:char;
 chet:integer;
label lb;

procedure create;
 begin
  first:=nil;
  last:=nil;
 end;

procedure add(vr:longint);
 begin
  new(p);
  p^.inf:=vr;
  p^.link:=nil;
  if last =nil then first:=p
  else last^.link:=p;
  last:=p;
 end;

procedure show;
 begin
  clrscr;
  p1:=first;
  while p1<>nil do
  begin
  vq:=p1^.inf;
  writeln(vq);
  p2:=p1;
  p1:=p2^.link;
  end;
 end;

 procedure del(var val:longint);
 begin
 val:=first^.inf;
 p:=first;
 first:=p^.link;
 if first=nil then last:=nil;
 dispose(p);
 end;

begin
vxod:=false;
lb:clrscr;
writeln('                            Выберите пункт:');
writeln('                          (1) Создание очереди');
writeln('                          (2) Добавление элемента');
writeln('                          (3) Удаление последнего элемента');
writeln('                          (4) Вывод очереди на экран');
writeln('                          (5) Выход');
c:=readkey;

if c='1'then
begin
clrscr;
create;
vxod:=true;
writeln('Создана новая очередь');
writeln('Вводите эл-ты очереди до Esc');
chet:=0;
repeat
readln(vq);
add(vq);
inc(chet);
until readkey=#27;
goto lb;
end else

if c='2'then
begin
clrscr;
if vxod=false then
begin
gotoxy(30,13);
write('Очередь не создана');
readkey;
goto lb;
end;
writeln('Вводите эл-ты очереди до Esc');
repeat
readln(vq);
add(vq);
inc(chet);
until readkey=#27;
goto lb;
end;

if c='3'then
begin
gotoxy(30,13);
if chet=0 then
begin
writeln('Очередь пуста');
readkey;
goto lb;
end;
del(vq);
dec(chet);
writeln('Элемент очереди ',vq,' удален');
readkey;
clrscr;
goto lb;
end;

if c='4' then
begin
clrscr;
writeln('Элементы очереди');
show;
readkey;
goto lb;
end;

if c='5'then exit
else goto lb;

end.

Leave a Comment

73 − 72 =