Advertisement
EstebanT

Untitled

Jan 26th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.09 KB | None | 0 0
  1. program pacial_TAD
  2. Uses TAD Insumo;
  3. type
  4.  
  5. lista = ^nodo
  6. nodo = record
  7.       nombre:string;
  8.       direccion:string;
  9.       li:Listai;
  10.       sig:lista;
  11.       end;
  12.  
  13. listai= ^nodo
  14. nodo  = record
  15.       i:insu;
  16.       sig:listai;
  17.       end;
  18.  
  19. listaE = ^nodo
  20. nodo   = record
  21.         nombre:string;
  22.         direccion:string;
  23.         a:arbol;
  24.         sig:listae;
  25.         end;
  26.  
  27. arbol = ^nodo
  28. nodo  = record
  29.       precio:real;
  30.       li:listai;
  31.       hd:nil;
  32.       hi:nil;
  33.       end;
  34.  
  35. var l:lista; li:listaI; le:listaE; a:arbol; i,i2:insu; precio:real; direccion:string;
  36.  
  37. procedure crearArbol ( var a:arbol )
  38. begin
  39. a:= nil;
  40. end;
  41.  
  42. procedure incisoA (l:lista; var le:listae; precio:real; direccion:string )
  43. var act:string;
  44. begin
  45. while ( l <> nil ) do begin
  46.         act:= l^.nombre;
  47.         direccion:= l^.direccion;
  48.         while ( act = l^.nombre ) do
  49.                 while ( l^.li <> nil ) do begin
  50.                         precio:= verPrecio (l^.li.i);
  51.                         instertarListaE ( nombre, direccion, precio, l^.li, le);
  52.                         l^.li:= l^.li^.sig;
  53.                         end;
  54.             l:= l^.sig;
  55. end;
  56.  
  57. procedure instertarListaE ( nombre, direccion: string; precio:real; i:insu; var le:listaE )
  58. var act, ant, nue:listaE;
  59. begin
  60. new (nue);
  61. nue^.nombre:= nombre;
  62. nue^.direccion:= direccion;
  63. insertarArbol ( le^.a, precio, i );
  64. ant:= le;
  65. act:= le;
  66. while ( act <> nil ) and ( nombre > act^.nombre ) do begin
  67.         ant:= act;
  68.         act:= act^.sig;
  69.         end;
  70. if ( ant = act ) then begin
  71.     nue^.sig:= le;
  72.     le:= nue;
  73.     else begin
  74.          ant^.sig:= nue;
  75.          nue^.sig:= act;
  76.          end;
  77. end;
  78.  
  79. procedure insertarArbol ( var a:arbol; precio:real; i:insu )
  80. begin
  81. if ( a = nil ) then begin
  82.     a^.precio:= precio;
  83.     insertarListaI( a^.li, i);
  84.     a^.hi:= nil;
  85.     a^.hd:= nil;
  86.     else if ( precio = a^.precio ) then
  87.                 insertarListaI ( a^.li, i );
  88.         else if ( precio > a^.precio ) then
  89.                     insertarArbol ( a^.hd, precio, i );
  90.              else insertarArbol ( a^.hi, precio, i );
  91. end;
  92.  
  93. procedure insertarListaI ( var li:listaI; i:insu )
  94. var nue:listaI;
  95. begin
  96. new ( nue );
  97. asignar ( nue^.i; i)
  98. nue^.sig:= li;
  99. li:= nue;
  100. end;
  101.  
  102. procedure incisoB ( le: listaE )
  103. var total,max:integer; maxN, act: string;
  104. begin
  105. max:= -1;
  106. while ( le <> nil ) do begin
  107.         total:= 0;
  108.         act:= le^.nombre;
  109.         while ( act = le^.nombre ) do begin
  110.                 totalEnArbol ( le^.a, total),
  111.                 le:= le^.sig;
  112.                 if ( act <> le^.nombre ) then
  113.                     calcularMax(max, maxN, act, total);
  114. end;
  115. write ('La empresa que provee mas insumos es: ', maxN, 'con la cantidad de ', total, ' insumos.');
  116. end;
  117.  
  118. procedure totalEnArbol ( a:arbol, var total:integer)
  119. begin
  120. if ( a <> nil ) then
  121.     totalEnArbol(a^.hi, total);
  122.     totalEnArbol(a^.hd, total);
  123.     totalEnListaArbol( a^.li, total);
  124. end;
  125.  
  126. procedure totalEnListaArbol ( li:listaI, var total:integer )
  127. begin
  128. while ( li <> nil ) do begin
  129.         total:= total + 1;
  130.         li:= li^.sig;
  131.         end;
  132. end;
  133.  
  134. procedure incisoC ( var le:listaE)
  135. begin
  136. while ( le <> nil ) do begin
  137.         modificar ( le^.a);
  138.         le:= le^.sig;
  139.         end;
  140. end;
  141.  
  142. procedure modificar ( var a: arbol )
  143. begin
  144. if ( a <> nil ) then
  145.     modificarLi(a^.hi);
  146.     modificar (a^.hd);
  147.     modificar (a^.hi);
  148.     end;
  149. end;
  150.  
  151. procedure modificarLi ( var li:listaI )
  152. var nN:string;
  153. begin
  154. nN:='Papel A4';
  155. while ( li <> nil ) do
  156.         if ( verCategoria (li^.i) = 10 ) then
  157.             modNombre (li^.i, nN);
  158. end;
  159.  
  160. procedure incisoD ( le:listaE )
  161. var act:string;
  162. begin
  163. while ( le <> nil ) do begin
  164.         act:= le^.nombre;
  165.         while ( act = le^.nombre ) do begin
  166.                 informarArbol ( le^.a ),
  167.                 le:= le^.sig;
  168.                 end;
  169.         end;
  170. end;
  171.  
  172. procedure informarArbol ( a:arbol )
  173. begin
  174. if ( a <> nil ) then
  175.     if ( a^.precio > 25 ) then
  176.         informarArbol(a^.hd);
  177.         informarArbol(a^.hi);
  178.         informarListaI(a^.li);
  179.     else if ( a^.precio < 25 ) then
  180.             informarArbol(a^.hd);
  181. end;
  182.  
  183. procedure informarListaI ( li: listaI )
  184. begin
  185. while ( li <> nil ) do begin
  186.         informar (l^.i);
  187.         li:= li^.sig;
  188.         end;
  189. end;
  190.  
  191. procedure informar ( i:insu )
  192. var nom, descripcion: string; precio:real; categoria:integer;
  193. begin
  194. verNombre (i,nom);
  195. verDescripcion(i,descripcion);
  196. precio:= verPrecio(i);
  197. categoria:= verCategoria(i);
  198. writeln('Nombre: ', nom);
  199. writeln('Descripcion: ', descripcion);
  200. writeln('Categoria: ', categoria);
  201. writeln('Precio: ', precio);
  202. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement