program ochered;
uses crt;
type
PtrNode=^Node;
Node=record;
Info: Integer;
Next: PetrNode;
end;
procedure prn_q(G: PtrNode);
var
t: PtrNode;
begin
t: G;
while t<>Nil do
begin
write(t^.Info:5);
t:=t^.Next;
end;
writeln;
end;
var
Q,P: PtrNode;
HQ,HP: PtrNode;
Tek: PtrNode;
n1, n2, i: Integer;
begin
clrscr;
Q:=Nil;
HQ:=Nil;
repeat
write('vvedite kol-vo elementov v ocheredi Q: ');
readln(n1);
until n1>0;
i:=0;
while i<n1 do
begin
New(Tek);
Tek^.Info:=random(100);
Tek^.Next:=Nil;
if Q=Nil then
begin
Q:=Tek;
HQ:=Tek;
end
else
begin
HQ^.Next:=Tek;
HQ:=Tek;
end;
i:=i+1;
end;
writeln('sozdana ochered Q: ');
prn_q(Q);
P:=Nil;
HP:=Nil;
repeat
write('vvedite kol-vo elementov v ocheredi P(ne menshe 4): ');
readln(n2);
until n2>=4;
i:=0;
while i<n2 do
begin
New(Tek);
Tek^.Info:=random(100);
Tek^.Next:=Nil;
if P=Nil then
begin
P:=Tek;
HP:=Tek;
end
else
begin
HP^.Next:=Tek;
HP:=Tek;
end;
i:=i+1;
end;
writeln(sozdana ochered P: ');
prn_q(P);
for i:=1 to 3 do
begin
Tek:=P;
HQ^.Next:=Tek;
HQ:=Tek;
P:=P^.Next;
HQ^.Next:=Nil;
end;
writeln('ochered P posle udalenia is nee 3 elementov: ');
prn_q(P);
writeln('ochered Q posle dobavlenia v nee 3 elementov: ');
prn_q(Q);
readln;
end.