Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Liste semplici - LISTE.PAS

LISTE.PAS

Caricato da: Poggi Marco
Scarica il programma completo

  1. program ListeSemplici;
  2. uses crt;
  3. type tsms=string[120];
  4.      puntatore=^elemento;
  5.  
  6.      elemento=record
  7.       num:real;
  8.       next:puntatore;
  9.      end;
  10.  
  11. var InList:puntatore;
  12.     e:elemento;
  13.  
  14. procedure pausa(frase:tsms; x,y:word);
  15. begin
  16.  gotoxy(x, y);
  17.  write(frase);
  18.  repeat ; until keypressed;
  19.  writeln(' '+readkey);
  20. end;
  21.  
  22. procedure stampa(k:puntatore);
  23. var co:word;
  24. begin
  25.  co:=0;
  26.  writeln('----------');
  27.  while (k<>nil) do
  28.  begin
  29.   writeln('Numero: ',k^.num:6:2);
  30.   k:=k^.next;
  31.   inc(co);
  32.   if co mod 27=0 then pausa('Premi un tasto per continuare...', 1, WhereY);
  33.  end;
  34.  writeln('----------');
  35.  writeln('Lista formata da ',co,' elementi.');
  36. end;
  37.  
  38. procedure InsTesta(var k:puntatore; e:integer);
  39. var nodo:puntatore;
  40. begin
  41.  nodo:=nil;
  42.  new(nodo);
  43.  nodo^.num:=e;
  44.  nodo^.next:=k;
  45.  k:=nodo;
  46. end;
  47.  
  48. procedure CancellaLista(k:puntatore);
  49. var vnodo:puntatore;
  50.     co:word;
  51. begin
  52.  co:=0;
  53.  while(k<>nil) do
  54.  begin
  55.   vnodo:=k;
  56.   k:=k^.next;
  57.   dispose(vnodo);
  58.   inc(co);
  59.  end;
  60.  writeln;
  61.  writeln('Eliminati ',co,' elementi.');
  62. end;
  63.  
  64. function InsCoda(k:puntatore; e:integer):boolean;
  65. var ch:boolean;
  66.     nunodo:puntatore;
  67. begin
  68.  ch:= (k<>nil); (* controlla se la lista Š vuta *)
  69.  if ch then
  70.  begin
  71.   new(nunodo);
  72.   nunodo^.num:=e;
  73.   nunodo^.next:=nil;
  74.   while (k^.next<>nil) do k:=k^.next;
  75.   k^.next:=nunodo;
  76.  end;
  77.  InsCoda:=ch;
  78. end;
  79.  
  80. procedure CaricaLista(var p:puntatore; fine:word);
  81. var i:word;
  82. begin
  83.  for i:=0 to fine do
  84.  begin
  85.   if not InsCoda(p, i) then InsTesta(p, i);
  86.  end;
  87. end;
  88.  
  89. begin
  90.  clrscr;
  91.  InList:=nil; (* lista vuota *)
  92.  
  93.  CaricaLista(InList, 5);
  94.  
  95.  stampa(InList);
  96.  
  97.  CancellaLista(InList);
  98.  InList:=nil;
  99.  pausa('Fine del programma.', 5, wherey+3);
  100. end.