program ListeSemplici;
uses crt;
type tsms=string[120];
puntatore=^elemento;
elemento=record
num:real;
next:puntatore;
end;
var InList:puntatore;
e:elemento;
procedure pausa(frase:tsms; x,y:word);
begin
gotoxy(x, y);
write(frase);
repeat ; until keypressed;
writeln(' '+readkey);
end;
procedure stampa(k:puntatore);
var co:word;
begin
co:=0;
writeln('----------');
while (k<>nil) do
begin
writeln('Numero: ',k^.num:6:2);
k:=k^.next;
inc(co);
if co mod 27=0 then pausa('Premi un tasto per continuare...', 1, WhereY);
end;
writeln('----------');
writeln('Lista formata da ',co,' elementi.');
end;
procedure InsTesta(var k:puntatore; e:integer);
var nodo:puntatore;
begin
nodo:=nil;
new(nodo);
nodo^.num:=e;
nodo^.next:=k;
k:=nodo;
end;
procedure CancellaLista(k:puntatore);
var vnodo:puntatore;
co:word;
begin
co:=0;
while(k<>nil) do
begin
vnodo:=k;
k:=k^.next;
dispose(vnodo);
inc(co);
end;
writeln;
writeln('Eliminati ',co,' elementi.');
end;
function InsCoda(k:puntatore; e:integer):boolean;
var ch:boolean;
nunodo:puntatore;
begin
ch:= (k<>nil); (* controlla se la lista Š vuta *)
if ch then
begin
new(nunodo);
nunodo^.num:=e;
nunodo^.next:=nil;
while (k^.next<>nil) do k:=k^.next;
k^.next:=nunodo;
end;
InsCoda:=ch;
end;
procedure CaricaLista(var p:puntatore; fine:word);
var i:word;
begin
for i:=0 to fine do
begin
if not InsCoda(p, i) then InsTesta(p, i);
end;
end;
begin
clrscr;
InList:=nil; (* lista vuota *)
CaricaLista(InList, 5);
stampa(InList);
CancellaLista(InList);
InList:=nil;
pausa('Fine del programma.', 5, wherey+3);
end.