Pascal/Turbo Pascal - Ayuda con Programa de Arreglos y Listas enlazadas

 
Vista:

Ayuda con Programa de Arreglos y Listas enlazadas

Publicado por Miguel (1 intervención) el 16/05/2013 18:46:52
Hola Ramon como estas, he visto como has ayudado a todos y de verdad que es excelente, ojala me puedas ayudar a mi con esto te lo agradeceria full, me mandaron a hacer esto,

Crear un programa donde usando listas encadenadas se obtenga lo siguiente:

- Menú donde se muestren las siguientes opciones
1.- Crear lista:
*Lista con números impares
*Lista con números aleatorios
*Lista con múltiplos de 10
2.- Modificar elemento de cualquiera de las 3 listas anteriores dada la posición del elemento
3.- Ordenar de menor a mayor cualquiera de las 3 listas anteriores
4.- Buscar un elemento de cualquiera de las 3 listas anteriores, indicar posición, cantidad de veces que se encuentra
5.- Incluir un elemento al final de cualquiera de las 3 listas anteriores
6.- Borrar un elemento al principio de cualquiera de las 3 listas anteriores
7.- Vaciar lista (cualquiera de las 3 listas anteriores)
8.- Salir del sistema

Se debe manejar ciclos, condicionales validando los valores introducidos, listas simples enlazadas, crear menú de opciones, colocar comentarios a detalle, colocar la identificación necesaria para que el programa se comprenda perfectamente, entre otros puntos.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Ayuda con Programa de Arreglos y Listas enlazadas

Publicado por ramon (2158 intervenciones) el 17/05/2013 13:19:31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
{Mira esto si te sirve modifica los datos entrados o sea datos pásalo a integer o real como
 lo quieras si esto no te sirve dímelo.}
 
program listassimples;
uses
    crt;
  type
     punteroejemp = ^ejemplo;
     ejemplo = record
           datos : string;
           sig : punteroejemp;
         end;
 
var
     tecla : char;
     prime, anter, actu : punteroejemp;
 
 
 
procedure otroregistroentra;
   procedure entramosdatos;
   begin
       with actu^ do
       begin
          write('Introduzca Datos : ');
          readln(datos);
       end;
   end;
begin
   if prime = nil then
   begin
       new(actu);
       entramosdatos;
       prime := actu;
       actu^.sig := nil;
      end
   else
      begin
          anter := actu;
          new(actu);
          entramosdatos;
          anter^.sig := actu;
          actu^.sig := nil;
      end;
    end;
 
procedure listardatos;
    var
      ver : punteroejemp;
    begin
       ver := prime;
       while ver <> nil do
       begin
          with ver^ do
          writeln(datos);
          ver := ver^.sig;
        end;
        writeln;
        writeln('Pulse [Enter]');
        readln;
     end;
 
procedure insertaprimero(entrada : string);
   var
      pt : punteroejemp;
    begin
        new(pt);
        pt^.datos := entrada;
        pt^.sig := prime;
        prime := pt;
    end;
 
procedure insertafinal(entrada : string);
    var
      pt : punteroejemp;
    begin
        new(pt);
        pt^.datos := entrada;
        actu^.sig := pt;
        pt^.sig := nil;
        actu := pt;
    end;
 
procedure insertamosporordendebalor(entrada : string);
    var
      rr, pp, pt : punteroejemp;
      nofin, salir : boolean;
    begin
       new(pt);
       pt^.datos := entrada;
       pp := prime;
       rr := prime;
       if pp^.datos > entrada then
       begin
          insertaprimero(entrada);
       end
     else
         begin
         salir := false;
         nofin := false;
     repeat
         rr := pp;
         pp := pp^.sig;
         if pp^.datos > entrada then
         begin
            salir := true;
            nofin := true;
         end;
     until (pp^.sig = nil) or (salir = true);
      if (salir = false) and (nofin = false) then
      begin
         insertafinal(entrada);
      end
    else
       begin
          pt^.sig := pp;
          rr^.sig := pt;
       end;
    end;
  end;
 
procedure insertaregistro;
   var
     dat : string;
     tt : char;
   begin
       clrscr;
       writeln;
       write('Insertamos Entre Datos : ');
       readln(dat);
       writeln;
       writeln('  Pulse  1 = Al Principio   2 = Al Final   3 = Ordenado ',
       '  4 = Nada');
       writeln('  Elija Opcion');
       repeat
       tt := readkey
       until tt in[#49..#52];
    case tt of
  #49 : insertaprimero(dat);
  #50 : insertafinal(dat);
  #51 : insertamosporordendebalor(dat);
  #52 :;
     end;
   end;
 
 
   begin
       prime := nil;
   repeat
        clrscr;
          repeat
            write('1 = entrar datos  2 = listar datos  3 = Insertar   4  = final');
            tecla := readkey;
          until tecla in[#49..#52];
      if tecla = #49 then
      begin
         clrscr;
         otroregistroentra;
      end;
      if tecla = #50 then
      begin
         clrscr;
         listardatos;
      end;
      if tecla = #51 then
      begin
          clrscr;
          insertaregistro;
      end;
      until tecla = #52;
   end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con Programa de Arreglos y Listas enlazadas

Publicado por ramon (2158 intervenciones) el 22/05/2013 13:43:24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
{A qui tienes completo}
 
 program punteros;
  uses
    crt;
   type
      impa = ^impares;
      impares = record
            numin : longint;
            sigin : impa;
           end;
 
       alea = ^aleator;
       aleator = record
            numal : longint;
            sigal : alea;
           end;
 
       mul10 = ^multi10;
       multi10 = record
            num10 : longint;
            sig10 : mul10;
           end;
 
 var
   orme, modme, priim, antim, actim : impa;
   ormt, modmt, prial, antal, actal : alea;
   ormk, modmk, pri10, ant10, act10 : mul10;
 
 
   procedure inicioa_nil;
   begin
      priim := nil;
      prial := nil;
      pri10 := nil;
   end;
 
   procedure crea_lista(cual : char);
   var
      num : longint;
   begin
      cual := upcase(cual);
      case cual of
   'I' : begin
           write('    Entre Numero Impar : ');
           readln(num);
           if num mod 2 <> 0 then
           begin
           if priim = nil then
           begin
              new(actim);
              actim^.numin := num;
              priim := actim;
              actim^.sigin := nil;
              end
           else
              begin
              antim := actim;
              new(actim);
              actim^.numin := num;
              antim^.sigin := actim;
              actim^.sigin := nil;
              end;
            end
         else
            begin
                 writeln;
                 writeln('   Elnumero Entrado No Es Impar No se Guarda ');
                 writeln('   Pulse Una [Tecla]');
                 readkey;
             end;
         end;
   'A' : begin
           write('    Entre Numero Aleatorio : ');
           readln(num);
           if prial = nil then
           begin
              new(actal);
              actal^.numal := num;
              prial := actal;
              actal^.sigal := nil;
              end
          else
             begin
              antal := actal;
              new(actal);
              actal^.numal := num;
              antal^.sigal := actal;
              actal^.sigal := nil;
             end;
         end;
   'M' : begin
           write('    Entre Numero Multiplo de 10 : ');
           readln(num);
           if num mod 10 = 0 then
           begin
           if pri10 = nil then
           begin
              new(act10);
              act10^.num10 := num;
              pri10 := act10;
              act10^.sig10 := nil;
              end
            else
               begin
                 ant10 := act10;
                 new(act10);
                 act10^.num10 := num;
                 ant10^.sig10 := act10;
                 act10^.sig10 := nil;
              end;
            end
          else
             begin
                 writeln;
                 writeln('   Elnumero Entrado No Es Multiplo De 10 No se Guarda ');
                 writeln('   Pulse Una [Tecla]');
                 readkey;
             end;
           end;
         end;
      end;
 
   procedure Modificar_elemento(cual : char);
   var
     modi, nun : longint;
     modifi : boolean;
   begin
       cual := upcase(cual);
       modifi := false;
       clrscr;
       write('   Entre el numero del elemento a modificar : ');
       readln(nun);
   case cual of
 'I' : begin
       modme := priim;
       while modme <> nil do
       begin
          if modme^.numin = nun then
          begin
             write('   El Nuevo Numeros Impares : ');
             readln(modme^.numin);
             if modme^.numin  mod 2 <> 0 then
             begin
             modifi := true;
             break;
             end
          else
             begin
                writeln('  El numero entrado no es impar pulse una [Tecla]');
                readkey;
                break;
             end;
          end;
           modme := modme^.sigin;
         end;
         if modifi = false then
         begin
            clrscr;
            writeln('  El Numero Entrado No Existe Pulse Una [Tecla]');
            readkey;
         end;
       end;
 'A' : begin
       modmt := prial;
       while modmt <> nil do
       begin
          if modmt^.numal = nun then
          begin
             write('   Entre Nuevo Numeros Aleatorios : ');
             readln(modmt^.numal);
             modifi := true;
             break;
          end;
           modmt := modmt^.sigal;
         end;
         if modifi = false then
         begin
            clrscr;
            writeln('  El Numero Entrado No Existe Pulse Una [Tecla]');
            readkey;
         end;
       end;
 'M' : begin
       modmk := pri10;
       while modmk <> nil do
       begin
          if modmk^.num10 = nun then
          begin
             write('   Entre Nuevo Numeros Multiplo 10 : ');
             readln(modmk^.num10);
             if modmk^.num10 mod 10 <> 0 then
             begin
                writeln('  El numero entrado no es multiplo de 10 ',
                                                'pulse una [Tecla]');
                readkey;
                break;
             end
          else
             begin
             modifi := true;
             break;
             end;
          end;
           modmk := modmk^.sig10;
         end;
         if modifi = false then
         begin
            clrscr;
            writeln('  El Numero Entrado No Existe Pulse Una [Tecla]');
            readkey;
         end;
       end;
     end;
   end;
 
  procedure Ordenar_de_menor_a_mayor(cual : char);
  var
    tpom : longint;
  begin
     cual := upcase(cual);
    case cual of
  'I' : begin
         modme := priim;
         orme := modme^.sigin;
         while modme <> nil do
         begin
           while orme <> nil do
           begin
              if modme^.numin > orme^.numin then
              begin
                 tpom := modme^.numin;
                 modme^.numin := orme^.numin;
                 orme^.numin := tpom;
              end;
              orme := orme^.sigin;
           end;
            modme := modme^.sigin;
            orme := modme^.sigin;
         end;
        end;
  'A' : begin
         modmt := prial;
         ormt := modmt^.sigal;
         while modmt <> nil do
         begin
           while ormt <> nil do
           begin
              if modmt^.numal > ormt^.numal then
              begin
                 tpom := modmt^.numal;
                 modmt^.numal := ormt^.numal;
                 ormt^.numal := tpom;
              end;
              ormt := ormt^.sigal;
           end;
            modmt := modmt^.sigal;
            ormt := modmt^.sigal;
         end;
        end;
  'M' : begin
         modmk := pri10;
         ormk := modmk^.sig10;
         while modmk <> nil do
         begin
           while ormk <> nil do
           begin
              if modmk^.num10 > ormk^.num10 then
              begin
                 tpom := modmk^.num10;
                 modmk^.num10 := ormk^.num10;
                 ormk^.num10 := tpom;
              end;
              ormk := ormk^.sig10;
           end;
            modmk := modmk^.sig10;
            ormk := modmk^.sig10;
         end;
       end;
     end;
  end;
 
  procedure Buscar_un_elemento(cual : char; nu : longint);
  var
    cont : longint;
  begin
     cual := upcase(cual);
     cont := 0;
     case cual of
  'I' : begin
          modme := priim;
          while modme <> nil do
          begin
             if modme^.numin = nu then
             begin
                writeln(' Posicion y Numero : ',cont,' = ',modme^.numin);
                cont := cont + 1;
             end;
             modme := modme^.sigin;
          end;
            writeln;
            writeln('   Aparece : ',cont);
            writeln;
            writeln('   Pulse Una [Tecla]');
            readkey;
        end;
  'A' : begin
          modmt := prial;
          while modmt <> nil do
          begin
             if modmt^.numal = nu then
             begin
                writeln(' Posicion y Numero : ',cont,' = ',modmt^.numal);
                cont := cont + 1;
             end;
             modmt := modmt^.sigal;
          end;
            writeln;
            writeln('   Aparece : ',cont);
            writeln;
            writeln('   Pulse Una [Tecla]');
            readkey;
        end;
  'M' : begin
          modmk := pri10;
          while modmk <> nil do
          begin
             if modmk^.num10 = nu then
             begin
                writeln(' Posicion y Numero : ',cont,' = ',modmk^.num10);
                cont := cont + 1;
             end;
             modmk := modmk^.sig10;
          end;
            writeln;
            writeln('   Aparece : ',cont);
            writeln;
            writeln('   Pulse Una [Tecla]');
            readkey;
        end;
     end;
  end;
 
  procedure Incluir_un_elemento_al_final(cual : char; nu : longint);
  begin
      cual := upcase(cual);
      case cual of
  'I' : begin
           new(orme);
           orme^.numin := nu;
           actim^.sigin := orme;
           orme^.sigin := nil;
           actim := orme;
        end;
  'A' : begin
           new(ormt);
           ormt^.numal := nu;
           actal^.sigal := ormt;
           ormt^.sigal := nil;
           actal := ormt;
        end;
  'M' : begin
           new(ormk);
           ormk^.num10 := nu;
           act10^.sig10 := ormk;
           ormk^.sig10 := nil;
           act10 := ormk;
        end;
      end;
  end;
 
 procedure Borrar_un_elemento_al_principio(cual : char);
 begin
     cual := upcase(cual);
     case cual of
  'I' : begin
            orme := priim;
            orme := orme^.sigin;
            priim := orme;
        end;
  'A' : begin
           ormt := prial;
           ormt := ormt^.sigal;
           prial := ormt;
        end;
  'M' : begin
            ormk := pri10;
            ormk := ormk^.sig10;
            pri10 := ormk;
        end;
     end;
 end;
 
  procedure Vaciar_una_lista(cual : char);
  begin
      cual := upcase(cual);
     case cual of
  'I' : begin
            dispose(actim);
            priim := nil;
            actim := nil;
        end;
  'A' : begin
           dispose(actal);
           prial := nil;
           actal := nil;
        end;
  'M' : begin
            dispose(act10);
            pri10 := nil;
            act10 := nil;
        end;
     end;
  end;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con Programa de Arreglos y Listas enlazadas

Publicado por ramon (2158 intervenciones) el 22/05/2013 13:45:21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
{En dos partes esta la segunda}
 
  procedure presenta_lista(cual : char);
  begin
      cual := upcase(cual);
      case cual of
   'I' : begin
            modme := priim;
            clrscr;
            while modme <> nil do
            begin
               writeln('  Numero Impar : ',modme^.numin);
               modme := modme^.sigin;
            end;
             writeln;
             writeln('    Pulse una [Tecla]');
             readkey;
         end;
   'A' : begin
            modmt := prial;
            clrscr;
            while modmt <> nil do
            begin
               writeln('  Numero Impar : ',modmt^.numal);
               modmt := modmt^.sigal;
            end;
             writeln;
             writeln('    Pulse una [Tecla]');
             readkey;
         end;
   'M' : begin
            modmk := pri10;
            clrscr;
            while modmk <> nil do
            begin
               writeln('  Numero Impar : ',modmk^.num10);
               modmk := modmk^.sig10;
            end;
             writeln;
             writeln('    Pulse una [Tecla]');
             readkey;
         end;
      end;
  end;
 
   procedure menugeneral;
 var
   sal : boolean;
   tecc, tecla : char;
   nu : longint;
 begin
     sal := false;
     repeat
       clrscr;
       writeln('           **** Menu General ****');
       writeln;
       writeln('           1 = Crear listas');
       writeln('           2 = Modificar elemento de una lista');
       writeln('           3 = Ordenar de menor a mayor una lista');
       writeln('           4 = Buscar un elemento en la lista');
       writeln('           5 = Incluir un elemento al final de la lista');
       writeln('           6 = Borrar un elemento en la lista');
       writeln('           7 = Vaciar una lista');
       writeln('           8 = Ver toda una lista');
       writeln('           9 = Salir');
       writeln;
       writeln('           <<<< Elija Opcion >>>>');
       repeat
           tecla := readkey;
       until tecla in['1','2','3','4','5','6','7','8','9'];
       clrscr;
    case tecla of
  '1' : begin
            writeln('   Crear Lista De Numeros [I]=Impares ',
            ' [A]=Aleatorios  [M]=Multiplos');
            repeat
            tecc := upcase(readkey);
            until tecc in['I','A','M'];
            crea_lista(tecc);
        end;
  '2' : begin
            writeln('   Modificar Lista De Numeros [I]=Impares ',
            ' [A]=Aleatorios  [M]=Multiplos');
            repeat
            tecc := upcase(readkey);
            until tecc in['I','A','M'];
            Modificar_elemento(tecc);
         end;
  '3' : begin
          writeln('   Ordena Lista De Numeros [I]=Impares ',
            ' [A]=Aleatorios  [M]=Multiplos');
          repeat
            tecc := upcase(readkey);
          until tecc in['I','A','M'];
          Ordenar_de_menor_a_mayor(tecc);
        end;
  '4' : begin
           writeln('   Buscar Elemento en Lista [I]=Impares ',
            ' [A]=Aleatorios  [M]=Multiplos');
            repeat
            tecc := upcase(readkey);
            until tecc in['I','A','M'];
            writeln;
            write('   Entre Numero A Buscar : ');
            readln(nu);
            case tecc of
         'I' : begin
                if nu mod 2 <> 0 then
                Buscar_un_elemento(tecc,nu)
              else
                begin
                writeln('  El Numero Entrado No Es Impar');
                writeln('   Pulse Una [Tecla]');
                readkey;
                end;
               end;
         'A' : Buscar_un_elemento(tecc,nu);
         'M' : begin
                 if nu mod 10 = 0 then
                 Buscar_un_elemento(tecc,nu)
               else
                  begin
                    writeln('  El Numero Entrado No Es Multiplo de 10');
                    writeln('   Pulse Una [Tecla]');
                    readkey;
                end;
              end;
            end;
        end;
  '5' : begin
            writeln('   Inserta En Lista De Numeros [I]=Impares ',
            ' [A]=Aleatorios  [M]=Multiplos');
            repeat
            tecc := upcase(readkey);
            until tecc in['I','A','M'];
            writeln;
            write('   Entre Numero A Insertar : ');
            readln(nu);
            Incluir_un_elemento_al_final(tecc,nu);
        end;
  '6' : begin
            writeln('   Borrado Elemento En Lista [I]=Impares ',
            ' [A]=Aleatorios  [M]=Multiplos');
            repeat
            tecc := upcase(readkey);
            until tecc in['I','A','M'];
            Borrar_un_elemento_al_principio(tecc);
        end;
  '7' : begin
            writeln('   Borrado Una Lista  [I]=Impares ',
            ' [A]=Aleatorios  [M]=Multiplos');
            repeat
            tecc := upcase(readkey);
            until tecc in['I','A','M'];
            Vaciar_una_lista(tecc);
        end;
  '8' : begin
           writeln('   Presentar Una Lista  [I]=Impares ',
            ' [A]=Aleatorios  [M]=Multiplos');
            repeat
            tecc := upcase(readkey);
            until tecc in['I','A','M'];
            presenta_lista(tecc);
        end;
  '9' : sal := true;
   end;
   until sal = true;
   if actim <> nil then
   dispose(actim);
   if actal <> nil then
   dispose(actal);
   if act10 <> nil then
   dispose(act10);
 end;
 
 
  begin
     inicioa_nil;
     menugeneral;
  end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar