1 { algoritmos y programacion II - Catedra Carolo - PRACTICA }
\r\r
2 { PARCIAL 1 1ra Op CUAT 1 2000 }
\r\r
4 program A2000_C1_P1_1;
\r\r
6 uses SYSUTILS, CRT,
\r\r
7 T_COLORD_B1, T_LSC, TDA_GRAL;
\r\r
11 TClaseComando =( INS, INO, ORD, BUC, BUR, LIA, LID, LIC, BOR, MOV, LIM, MOC );
\r\r
13 { registro de entrada }
\r\r
15 comando:TClaseComando;
\r\r
18 nombre:string[40];
\r\r
19 movimiento: LSC_movimiento;
\r\r
20 strMovim: string[2];
\r\r
21 dni_hasta:longint;
\r\r
25 { este procedimiento lee una linea de texto y la convierte en un comando }
\r\r
26 { devuelve TRUE si mapeo correctamente, sino FALSE }
\r\r
27 function MapearComando( linea: String; VAR c: TComando ): boolean;
\r\r
29 strComando: string;
\r\r
36 { defino que comando es }
\r\r
37 strComando := copy( linea, 1,2 );
\r\r
39 if strComando='IN' then c.comando := INS
\r\r
40 else if strComando='OR' then c.comando := ORD
\r\r
41 else if strComando='LS' then c.comando := LIA
\r\r
42 else if strComando='LC' then c.comando := LIC
\r\r
43 else if strComando='BO' then c.comando := BOR
\r\r
44 else if strComando='MV' then c.comando := MOV
\r\r
45 else if strComando='MO' then c.comando := MOC
\r\r
46 else if strComando='LI' then c.comando := LIM
\r\r
49 { defino el DNI, nombre y hasta }
\r\r
50 strDNI := copy( linea, 3,8 );
\r\r
51 IF LeftStr( strDNI, 1 ) <> '*'
\r\r
52 THEN c.dni := strToIntDef( strDNI, -1 )
\r\r
54 c.strDni := strDni;
\r\r
56 strDNI := copy( linea, 52,8 );
\r\r
57 IF LeftStr( strDNI, 1 ) <> '*'
\r\r
58 THEN c.dni_hasta := strToIntDef( strDNI, -1 )
\r\r
59 ELSE c.dni_hasta := -2;
\r\r
61 IF (c.dni = -1 ) or (c.dni_hasta = -1 ) THEN ok := false;
\r\r
63 IF copy( linea, 11, 1 ) = '*'
\r\r
64 THEN c.nombre := '*'
\r\r
65 ELSE c.nombre := copy( linea, 11, 40 );
\r\r
67 { el tipo de movimiento }
\r\r
68 strMovim := copy( linea, 51, 1 );
\r\r
69 c.strMovim := strMovim;
\r\r
70 if strMovim='P' then c.movimiento := LSC_primero
\r\r
71 else if strMovim='S' then c.movimiento := LSC_siguiente
\r\r
72 else if strMovim<>'*' then ok := false;
\r\r
74 { writeln( 'dat:', c.nombre, ':', c.dni, ':', c.dni_hasta, ':', strMovim, ':', strComando,':' ); }
\r\r
75 MapearComando := ok;
\r\r
78 PROCEDURE inicializar( VAR archEnt: text; VAR archSal: text);
\r\r
80 nomArchEnt: string;
\r\r
81 nomArchSal: string;
\r\r
83 { busco los nombres de los archivos }
\r\r
84 nomArchEnt := ParamStr( 1 );
\r\r
85 nomArchSal := ParamStr( 2 );
\r\r
87 writeln( 'IN :', nomArchEnt );
\r\r
88 writeln( 'OUT:', nomArchSal );
\r\r
90 { preparo los archivos }
\r\r
91 assign ( archEnt, nomArchEnt );
\r\r
92 reset ( archEnt );
\r\r
93 assign ( archSal, nomArchSal );
\r\r
94 rewrite( archSal );
\r\r
97 PROCEDURE Ordenar_Lista( VAR l: LSC_Lista; VAR archSal: text );
\r\r
103 { inicializo la cola }
\r\r
104 COLAORD_inicializar( c );
\r\r
106 { pongo todos los registros en la cola }
\r\r
107 LSC_Mover_cte( l, LSC_primero, error );
\r\r
108 writeln('ahora empiezo a sacar de la lista');
\r\r
111 LSC_elem_cte( l, e );
\r\r
112 COLAORD_poner( c, e, error );
\r\r
113 IF error THEN writeln( archSal, 'ERROR ELEMENTO DUPLICADO [', devolver_clave_elem( e ), '] SERA DESCARTADO');
\r\r
114 LSC_Mover_cte( l, LSC_siguiente, error );
\r\r
117 writeln('ahora empiezo a poner de vuelta en la lista');
\r\r
118 { ahora limpio la lista y los pongo de vuelta ordenados }
\r\r
120 WHILE not COLAORD_Vacia( c )
\r\r
122 COLAORD_sacar( c, e );
\r\r
123 writeln('saque ', e.dni, ':',e.nombre);
\r\r
124 LSC_Insertar( l, LSC_siguiente, e );
\r\r
146 inicializar( archEnt, archSal);
\r\r
148 { creo la tabla donde voy a trabajar }
\r\r
149 LSC_Inicializar( t );
\r\r
151 { itero por la entrada }
\r\r
152 WHILE not eof( archEnt ) DO
\r\r
154 { leo la entrada }
\r\r
155 readln( archEnt, linea );
\r\r
157 IF not MapearComando( linea, c )
\r\r
159 writeln( archSal, 'ERROR MAP [', linea, ']');
\r\r
164 { ahora empiezo con el case de las operaciones }
\r\r
165 case c.comando of
\r\r
166 MOV:begin { mover corriente }
\r\r
167 writeln( archSal, 'MOV [', c.strMovim, ']' );
\r\r
168 if not LSC_vacia( t )
\r\r
170 LSC_mover_cte( t, c.movimiento, error );
\r\r
171 IF error THEN writeln( 'MOV ERROR' );
\r\r
174 writeln( 'ERROR: tabla vacia' );
\r\r
177 INS: BEGIN { tengo que insertar }
\r\r
178 str( c.dni:8 , c.strDni );
\r\r
179 writeln( archSal, 'INS [', c.strDni, ':', c.nombre, ':', c.strMovim, ']' );
\r\r
180 IF LSC_llena( t )
\r\r
181 THEN writeln( archSal, 'ERROR tabla llena')
\r\r
183 elem.dni := c.dni;
\r\r
184 elem.nombre := c.nombre;
\r\r
185 LSC_insertar( t, c.movimiento, elem );
\r\r
189 LIC: begin { listar corriente }
\r\r
190 if not LSC_VACIA( t )
\r\r
192 LSC_ELEM_CTE( t, elem );
\r\r
193 str( elem.dni:8 , c.strDni );
\r\r
194 writeln( archSal, 'LIC [', c.strDni, ':', elem.nombre,']' );
\r\r
196 else writeln( archSal, 'LIC ERROR vacia');
\r\r
199 LIA: begin { listar la tabla }
\r\r
200 writeln( archSal, 'LIS ASC');
\r\r
201 if not LSC_VACIA( t )
\r\r
203 LSC_MOVER_CTE( t, LSC_primero, error );
\r\r
204 LSC_ELEM_CTE( t, elem );
\r\r
206 while not error do
\r\r
208 str( elem.dni:8 , c.strDni );
\r\r
209 writeln( archSal, ' [', c.strDni, ':', elem.nombre,']' );
\r\r
210 LSC_MOVER_CTE( t, LSC_siguiente, error);
\r\r
211 LSC_ELEM_CTE( t, elem);
\r\r
216 ORD: begin { ordenar la tabla }
\r\r
217 writeln( archSal, 'ORD' );
\r\r
218 if not LSC_vacia( t )
\r\r
220 { este es la llamada al ejercicio }
\r\r
221 Ordenar_Lista( t, archSal );
\r\r
224 BOR: begin { borrar el corriente }
\r\r
225 writeln( archSal, 'BOR' );
\r\r
226 if not LSC_VACIA( t )
\r\r
228 LSC_BORRAR_CTE( t )
\r\r
229 else writeln( archSal, ' ERROR TABLA VACIA');
\r\r
232 MOC:begin { modificar el corriente }
\r\r
233 str( c.dni:8 , c.strDni );
\r\r
234 writeln( archSal, 'MOC [', c.strDni, ':', c.nombre, ']' );
\r\r
235 if not LSC_VACIA(t)
\r\r
237 elem.dni := c.dni;
\r\r
238 elem.nombre := c.nombre;
\r\r
239 LSC_MODIF_CTE( t, elem );
\r\r
241 else writeln( archSal, ' ERROR TABLA VACIA');
\r\r
244 LIM:begin { limpiar tabla }
\r\r
245 writeln( archSal, 'LIM' );
\r\r
251 { cierro los archivos }
\r\r
252 close( archEnt );
\r\r
253 close( archSal );
\r\r