Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.80 KB | None | 0 0
  1. unit unListDin;
  2.  
  3. interface
  4.  
  5. uses
  6.   StdCtrls, sysUtils;
  7.  
  8. type
  9.   PNodo = ^Nodo;
  10.   Nodo = record
  11.     Nombre: String;
  12.     NReg: Integer;
  13.     Promedio: Real;
  14.     CantMat: Integer;
  15.     Prox: Pnodo;
  16.   end;
  17.  
  18. // Crear lista vacia (con nodo auxiliar)
  19. procedure Crear(var P: PNodo);
  20. // Insercion tipo pila. Lista desordenada
  21. procedure Agregar_Des(P: PNodo; ANombre: String; ANReg: Integer;
  22.     APromedio: Real; ACantMat: Integer);
  23. // Insercion ordenada. Lista ordenada por numero de registro
  24. procedure Agregar_Ord(P: PNodo; ANombre: String; ANReg: Integer;
  25.     APromedio: Real; ACantMat: Integer);
  26. // Eliminar nodo segun el numero de registro
  27. function Eliminar_Nreg(P: PNodo; ANReg: Integer): boolean;
  28. // Eliminar nodo segun la posicion
  29. function Eliminar_Pos(P: PNodo; Posicion: Integer): boolean;
  30. // Devuelve la cantidad de nodos
  31. function Cant_Nodos(P: PNodo): Integer;
  32. // Busca un dato (alumno por numero de registro) y devuelve su posicion.
  33. // Si no lo encuentra devuelve el valor 0.
  34. function Buscar(P: PNodo; ANReg: Integer): Integer;
  35. // Elimina la lista completa
  36. procedure Eliminar_Lista(P: PNodo; Posicion: Integer);
  37. // Muesta la lista de alumnos
  38. procedure MostrarLista(P: PNodo;  var Memo: TMemo);
  39.  
  40. implementation
  41.  
  42. // Crear lista vacia (con nodo auxiliar)
  43. procedure Crear(var P: PNodo);
  44. begin
  45.   New(P);
  46.   P^.Prox:=nil;
  47. end;
  48.  
  49.  
  50. function crearNodo( ANombre: String; ANReg: Integer;
  51.     APromedio: Real; ACantMat: Integer):PNodo;
  52. var
  53.   x:PNodo;
  54. begin
  55.   new(x);
  56.   x^.Nombre := ANombre;
  57.   x^.NReg := ANReg;
  58.   x^.Promedio := APromedio;
  59.   x^.CantMat := ACantMat;
  60.   x^.Prox := nil;
  61.  
  62.   crearNodo := x;
  63. end;
  64.  
  65. // Insercion tipo pila. Lista desordenada
  66. procedure Agregar_Des(P: PNodo; ANombre: String; ANReg: Integer;
  67.     APromedio: Real; ACantMat: Integer);
  68. var
  69.   x,y:PNodo;
  70. begin
  71.   x := crearNodo(ANombre,ANReg,APromedio,ACantMat);
  72.   y := p^.Prox;
  73.   p^.prox := x;
  74.   x^.prox := y;
  75. end;
  76.  
  77. // Insercion ordenada. Lista ordenada por numero de registro
  78. procedure Agregar_Ord(P: PNodo; ANombre: String; ANReg: Integer;
  79.     APromedio: Real; ACantMat: Integer);
  80. begin
  81. end;
  82.  
  83. // Eliminar nodo segun el numero de registro
  84. function Eliminar_NReg(P: PNodo; ANReg: Integer): boolean;
  85. var
  86.   x, y: PNodo;
  87. begin
  88.   x:=P; y:=P^.Prox;
  89.   while (y<>nil) do
  90.   begin
  91.     if (y^.NReg=ANReg) then Break;
  92.     x:=y; y:=y^.Prox;
  93.   end;
  94.   if y<>nil then
  95.     begin
  96.       x^.Prox:=y^.Prox;
  97.       Dispose(y);
  98.       Eliminar_NReg:=true;
  99.     end else
  100.         Eliminar_NReg := false
  101. end;
  102.  
  103. // Eliminar nodo segun la posicion
  104. function Eliminar_Pos(P: PNodo; Posicion: Integer): boolean;
  105. var
  106.   i:integer;
  107.   inPos:boolean;
  108.   x,y:PNodo;
  109. begin
  110.   i := 1;
  111.   x := p;
  112.   inPos := false;
  113.   while(x^.Prox<>nil) and (not inPos) do
  114.   begin
  115.     if i = (Posicion) then
  116.       inPos := true
  117.     else
  118.       begin
  119.         x := x^.Prox;
  120.         i := i + 1;
  121.       end
  122.   end;
  123.   if inPos then
  124.     begin
  125.       y := x^.prox;
  126.       x^.prox := y^.prox;
  127.       dispose(y);
  128.     end;
  129.  
  130.   Eliminar_Pos := inPos;
  131. end;
  132.  
  133. // Devuelve la cantidad de nodos
  134. function Cant_Nodos(P: PNodo): Integer;
  135. begin
  136. end;
  137.  
  138. // Busca un dato (alumno por numero de registro) y devuelve su posicion.
  139. // Si no lo encuentra devuelve el valor 0.
  140. function Buscar(P: PNodo; ANReg: Integer): Integer;
  141. begin
  142. end;
  143.  
  144. // Elimina la lista completa
  145. procedure Eliminar_Lista(P: PNodo; Posicion: Integer);
  146. begin
  147. end;
  148.  
  149. // Muesta la lista de alumnos
  150. procedure MostrarLista(P: PNodo; var Memo: TMemo);
  151. var
  152.   cont: Integer;
  153.   x: PNodo;
  154.   Linea: String;
  155. begin
  156.   x:=P^.Prox; cont:=1;
  157.   Memo.Clear;
  158.   while (x<>nil) do
  159.   begin
  160.     Linea:=Format('%.3d) %s. Numero de registro: %d. Materias: %d. Promedio: %g',
  161.                      [Cont, x^.Nombre, x^.NReg, x^.CantMat, x^.Promedio]);
  162.     Memo.Lines.Add(Linea);
  163.     x:=x^.Prox; Inc(Cont);
  164.   end;
  165. end;
  166.  
  167. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement