type PUNTA=^nodo;
nodo= record
inf:char;
Q:pUNTA
end;
var p0, p, r:PUNTA;
n,i:INTEGER;
ch:CHAR;
begin
{costruzione della lista}
p0:=nil;
repeat read(ch); case ch of
'(': begin {impila/PUSH}
new(p); p^.inf:=ch; p^.q:=p0; p0:=p
end;
'(': if p0<>nil then begin {estrai/POP}
p:=p0; p0:=p^.q; dispose(p)
end;
else exit
end; {case}
writeln; {stampa impilata della lista via via generata}
r:=p0;
while r<>nil do begin
write(r^.inf);
r:=r^.q
end;
until ch=chr(13); {
writeln;
if p0=nil then write('OK!) else write('KO?');
end.
Nessun commento:
Posta un commento