Pascal/Turbo Pascal - Ordenamiento de registros

 
Vista:
sin imagen de perfil
Val: 31
Ha disminuido 1 puesto en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

Ordenamiento de registros

Publicado por Roberto (19 intervenciones) el 05/01/2016 19:35:29
Saludos a la comunidad de este foro, quisiera su ayuda en el metodo de ordenacion de registros, necesito ordenar por el numero de pasaporte. Ejemplo :
22098567 juan espinoza
23654000 elias mendoza

He intentado y no he podidio, por favor ayudenme. Este es mi programa.


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
{Programa incompleto , elaborado por El varon}
 
program El_Turista_Toursven;
  uses
     crt;
  type
            Elturista = record        {Registro de los datos de un turista}
               Numpas : longint;      {Indica el numero de pasaporte}
           NombApelli : string[60];  {Indica el Nombre y apellido}
             Origenpas:char;          {Indica el origen del pasaporte}
          end;
 
   const
      perso = 30;      {Aquí se indica la cantidad máxima de personas}
  var
    datosturis : array[1..perso] of  Elturista;
    t, cont : integer;
    tec : char;
    coven : longint;
 
  procedure incluir;
   var
   tese:char;
  begin
      clrscr;
      writeln('**** Entrada De Datos Del Turista ****');
      writeln;
      write('     Nombre Apellido     : ');
      readln(datosturis[cont].NombApelli);
      write('     Numero de pasaporte     : ');
      readln(datosturis[cont].Numpas);
      write('     Origen del pasaporte V / E     : ');
         repeat
           tese := upcase(readkey);
         until tese in['E','V'];
           write(tese);
           datosturis[cont].Origenpas := tese;
         readkey;
   end;
 
   procedure consultar(codi : longint);
   var
     encontrado : boolean;
   begin
       encontrado := false;
       for t := 1 to cont do
       begin
          if datosturis[t].Numpas = codi then
          begin
            encontrado := true;
            break;
          end;
       end;
       if encontrado = true then
       begin
          clrscr;
          writeln('<<< Los Datos Consultados Son >>>');
          writeln;
          writeln('  Nombre Apellido      = ',datosturis[t].NombApelli);
          writeln('  Numero de pasaporte  = ',datosturis[t].Numpas);
          writeln('  Origen del pasaporte = ',datosturis[t].Origenpas);
          writeln('<<<<<< Pulse [Enter] >>>>>>>');
          readln;
       end
     else
        begin
           clrscr;
           writeln('  Error El Codigo Insertado No Esta Pulse [Enter]');
           readln;
        end;
   end;
 
  procedure modificar(codi : longint);
  var
    pul : char;
    modi : boolean;
  begin
     modi := false;
     for t := 1 to cont do
     begin
        if datosturis[t].Numpas = codi then
        begin
           modi := true;
           break;
        end;
     end;
      if modi = true then
      begin
         repeat
         clrscr;
         writeln('**** Modificacion De Datos ****');
         writeln;
         writeln('  1 = Nombre y Apellido    ' ,datosturis[t].NombApelli);
         writeln('  2 = Numero de pasaporte  ' ,datosturis[t].Numpas);
         writeln('  3 = Origen del pasaporte  ' ,datosturis[t].Origenpas);
         writeln('  4 = finaliza');
         repeat
             pul := readkey;
         until pul in[#49..#52];
      case pul of
     #49 : begin
           write('  Nombre y Apellido     : ');
           readln(datosturis[t].NombApelli);
           end;
     #50 : begin
           write('  Numero de Pasaporte     : ');
           readln(datosturis[t].Numpas);
           end;
     #51 : begin
           write('  Origen del pasaporte     : ');
           readln(datosturis[t].Origenpas);
           end;
      end;
    until pul = #52;
    end
   else
      begin
         clrscr;
         writeln('  Error El Codigo Insertado No Esta Pulse [Enter]');
         readln;
      end;
  end;
 
  procedure eliminar(codi : longint);
  var
    pul : char;
    borra : boolean;
    corre : integer;
  begin
     borra := false;
     for t := 1 to cont do
     if datosturis[t].Numpas = codi then
     begin
        borra := true;
        break;
     end;
     if borra = true then
     begin
        clrscr;
        writeln('<<<<<<<< Anular Registro Vendedor >>>>>>>>>>');
        writeln;
        writeln('  Numero de pasaporte     = ',datosturis[t].Numpas);
        writeln;
        writeln('Desea Anular Este Turista [S/N]');
        repeat
           pul := upcase(readkey);
        until pul in['S','N'];
        if pul = 'S' then
        begin
           fillchar(datosturis[t],sizeof(datosturis[t]),0);
           corre := 1;
           for corre := t to cont do
           if datosturis[corre].Numpas > 0 then
           begin
              datosturis[corre] := datosturis[corre - 1];
           end;
            cont := cont - 1;
        end;
     end
   else
      begin
         clrscr;
         writeln('  Error El Codigo Insertado No Esta Pulse [Enter]');
         readln;
      end;
  end;
 
procedure ordenararray;
    {// ordenamiento burbuja por campo numero de pasaporte}
     var
       ordenado : boolean;
            aux : Elturista;
              i : integer;
    begin
       ordenado := false;
    while (not ordenado) do
    begin
      ordenado := true;
        for i := 1 to cont do
        begin
          if (datosturis[i].numpas > datosturis[i].numpas) then
          begin
             aux := datosturis[i + 1];
             datosturis[i + 1] := datosturis[i];
             datosturis[i] := aux;
             ordenado := false;
          end;
       end;
     end;
   end;
 
procedure mostrarorden;
var
i:integer;
 
begin
 
    writeLn('Los datos tras ordenar son: ');
    for i := 1 to cont do
        write(datosturis[i].Numpas, ' ',datosturis[i].NombApelli);
    writeLn;
end;
 
procedure contadores;
var
   t:integer;
   vene,extra:integer;
begin
    vene := 0;
    extra := 0;
 
   Writeln('Datos');
   writeln;
   for t := 1 to cont do
   begin
      if (datosturis[t].Origenpas='V') then
    begin
     vene := vene + 1;
     end
      else
    begin
     extra := extra + 1;
  end;
   end;
 
begin
   WriteLn('Cantidad de venezolanos ',vene);
   WriteLn('Cantidad de extranjeros ',extra);
   ReadLn;
end;
end;
 
  procedure menu;
  var
    tee : char;
    sas : boolean;
  begin
     sas := false;
   repeat
      clrscr;
      writeln('******* Menu General *********');
      writeln;
      writeln('   1 = INCLUIR');
      writeln('   2 = CONSULTAR');
      writeln('   3 = MODIFICAR');
      writeln('   4 = ELIMINAR');
      writeln('   5 = ORDENAR');
      writeln('   6 = CONTADOR');
      writeln('   7 = SALIR');
      writeln;
      writeln('<<<<< Elija Opcion >>>>>');
      repeat
         tee := readkey;
      until tee in[#49..#55];
  case tee of
 #49 : begin
         clrscr;
         cont := cont + 1;
         if cont > perso then
         cont := perso;
         incluir;
        end;
 #50 : begin
          clrscr;
          write('   Entre Numero de pasaporte : ');
          readln(coven);
          consultar(coven);
       end;
 #51 : begin
          clrscr;
          write('   Entre Numero de pasaporte : ');
          readln(coven);
          modificar(coven);
       end;
 #52 : begin
          clrscr;
          write('   Entre Numero de pasaporte : ');
          readln(coven);
          eliminar(coven);
       end;
 
 #53 : begin
          clrscr;
          ordenararray;
          mostrarorden;
       end;
 
 #54 : begin clrscr; contadores; end;
 
 #55 : sas := true;
   end;
   until sas = true;
  end;
 
 
   begin
       cont := 0;
       menu;
   end.
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
sin imagen de perfil

Ordenamiento de registros

Publicado por crack81 (58 intervenciones) el 06/01/2016 05:19:22
Hola te traigo una posible solucion pense implementarlo directamente en tu codigo pero te reservo esa experiencia, en este caso uso un arreglo de records y los ordeno con el algoritmo bubble sort

si tienes preguntas no dudes en avisar

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
type
  TTurista=Record
    nombre:string;
    pasaporte:LongInt;
  end;
 
  TListaTurista=array [0..10]of TTurista;
 
Procedure BubbleSort2(var numbers : TListaTurista; size : Integer);
Var
  i,j:Integer;
  temp:TTurista;
 
Begin
  for i:=1 to size-1  do
  begin
     for j:=0 to size-2 do
     begin
        if numbers[j].pasaporte> numbers[j+1].pasaporte then
        begin
          temp:=numbers[j];
          numbers[j]:= numbers[j+1];
          numbers[j+1]:=temp;
        end;
     end;
  end;
 
End;
 
 
var
  i:integer;
  lista:TListaTurista;
  contador:Integer;
begin
  contador:=0;
  lista[0].nombre:='jose';
  lista[0].pasaporte:=2;
 
  lista[1].nombre:='maria';
  lista[1].pasaporte:=1;
 
  lista[2].nombre:='juan';
  lista[2].pasaporte:=3;
 
  lista[3].nombre:='roberto';
  lista[3].pasaporte:=5;
 
  lista[4].nombre:='carlos';
  lista[4].pasaporte:=4;
 
  BubbleSort2(lista,5);
  WriteLn('Lista ordenada');
  for i:=0 to 4 do
  begin
   WriteLn('Nombre ',lista[i].nombre,' pasaporte ',lista[i].pasaporte);
  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
sin imagen de perfil
Val: 31
Ha disminuido 1 puesto en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

Ordenamiento de registros

Publicado por Roberto (19 intervenciones) el 06/01/2016 14:51:30
ok, gracias. voy a probar tu algoritmo.
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
sin imagen de perfil
Val: 31
Ha disminuido 1 puesto en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

Ordenamiento de registros

Publicado por Roberto (19 intervenciones) el 06/01/2016 21:47:27
Encontré una solución en este foro y me sirvió, gracias por tu ayuda crack.

http://www.lawebdelprogramador.com/foros/Pascal-Turbo-Pascal/1360623-Ordenar-arrays-de-registros.html

Ramón es un genio en programación.


Si alguien le interesa este es mi programa modificado.

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
{Programa incompleto , elaborado por El Varon}
 
program El_Turista_Toursven;
  uses
     crt;
  type
            Elturista = record        {Registro de los datos de un turista}
               Numpas : longint;      {Indica el numero de pasaporte}
           NombApelli : string[60];  {Indica el Nombre y apellido}
             Origenpas:char;          {Indica el origen del pasaporte}
          end;
 
   const
      perso = 30;      {Aquí se indica la cantidad máxima de personas}
  var
    datosturis : array[1..perso] of  Elturista;
    t, cont : integer;
    tec : char;
    coven : longint;
 
  procedure incluir;
   var
   tese:char;
  begin
      clrscr;
      writeln('**** Entrada De Datos Del Turista ****');
      writeln;
      write('     Nombre Apellido     : ');
      readln(datosturis[cont].NombApelli);
      write('     Numero de pasaporte     : ');
      readln(datosturis[cont].Numpas);
      write('     Origen del pasaporte V / E     : ');
         repeat
           tese := upcase(readkey);
         until tese in['E','V'];
           write(tese);
           datosturis[cont].Origenpas := tese;
         readkey;
   end;
 
 procedure ordenarregistro;
var
 aux : Elturista;
   i, t, r : integer;
   begin
       for t := 1 to cont do
         for r := cont downto t + 1 do
         if datosturis[t].numpas < datosturis[r].numpas then
         begin
             aux := datosturis[t];
             datosturis[t] := datosturis[r];
             datosturis[r] := aux;
         end;
   end;
 
   procedure consultar(codi : longint);
   var
     encontrado : boolean;
   begin
       encontrado := false;
       for t := 1 to cont do
       begin
          if datosturis[t].Numpas = codi then
          begin
            encontrado := true;
            break;
          end;
       end;
       if encontrado = true then
       begin
          clrscr;
          writeln('<<< Los Datos Consultados Son >>>');
          writeln;
          writeln('  Nombre Apellido      = ',datosturis[t].NombApelli);
          writeln('  Numero de pasaporte  = ',datosturis[t].Numpas);
          writeln('  Origen del pasaporte = ',datosturis[t].Origenpas);
          writeln('<<<<<< Pulse [Enter] >>>>>>>');
          readln;
       end
     else
        begin
           clrscr;
           writeln('  Error El Codigo Insertado No Esta Pulse [Enter]');
           readln;
        end;
   end;
 
  procedure modificar(codi : longint);
  var
    pul : char;
    modi : boolean;
  begin
     modi := false;
     for t := 1 to cont do
     begin
        if datosturis[t].Numpas = codi then
        begin
           modi := true;
           break;
        end;
     end;
      if modi = true then
      begin
         repeat
         clrscr;
         writeln('**** Modificacion De Datos ****');
         writeln;
         writeln('  1 = Nombre y Apellido    ' ,datosturis[t].NombApelli);
         writeln('  2 = Numero de pasaporte  ' ,datosturis[t].Numpas);
         writeln('  3 = Origen del pasaporte  ' ,datosturis[t].Origenpas);
         writeln('  4 = finaliza');
         repeat
             pul := readkey;
         until pul in[#49..#52];
      case pul of
     #49 : begin
           write('  Nombre y Apellido     : ');
           readln(datosturis[t].NombApelli);
           end;
     #50 : begin
           write('  Numero de Pasaporte     : ');
           readln(datosturis[t].Numpas);
           end;
     #51 : begin
           write('  Origen del pasaporte     : ');
           readln(datosturis[t].Origenpas);
           end;
      end;
    until pul = #52;
    end
   else
      begin
         clrscr;
         writeln('  Error El Codigo Insertado No Esta Pulse [Enter]');
         readln;
      end;
  end;
 
  procedure eliminar(codi : longint);
  var
    pul : char;
    borra : boolean;
    corre : integer;
  begin
     borra := false;
     for t := 1 to cont do
     if datosturis[t].Numpas = codi then
     begin
        borra := true;
        break;
     end;
     if borra = true then
     begin
        clrscr;
        writeln('<<<<<<<< Anular Registro Vendedor >>>>>>>>>>');
        writeln;
        writeln('  Numero de pasaporte     = ',datosturis[t].Numpas);
        writeln;
        writeln('Desea Anular Este Turista [S/N]');
        repeat
           pul := upcase(readkey);
        until pul in['S','N'];
        if pul = 'S' then
        begin
           fillchar(datosturis[t],sizeof(datosturis[t]),0);
           corre := 1;
           for corre := t to cont do
           if datosturis[corre].Numpas > 0 then
           begin
              datosturis[corre] := datosturis[corre - 1];
           end;
            cont := cont - 1;
        end;
     end
   else
      begin
         clrscr;
         writeln('  Error El Codigo Insertado No Esta Pulse [Enter]');
         readln;
      end;
  end;
 
  procedure mostraresultados;
   var
      d : integer;
   begin
       writeln('.... Datos ordenados .....');
       writeln;
       for d := 1 to cont do
       writeln(datosturis[d].numpas,' ',datosturis[d].NombApelli);
       writeln;
 
       writeln;
 
       writeln('*** Pulse [Enter] ***');
       readln;
   end;
 
procedure contadores;
var
   t:integer;
   vene,extra:integer;
begin
    vene := 0;
    extra := 0;
 
   Writeln('Datos');
   writeln;
   for t := 1 to cont do
   begin
      if (datosturis[t].Origenpas='V') then
    begin
     vene := vene + 1;
     end
      else
    begin
     extra := extra + 1;
  end;
   end;
 
begin
   WriteLn('Cantidad de venezolanos ',vene);
   WriteLn('Cantidad de extranjeros ',extra);
   ReadLn;
end;
end;
 
  procedure menu;
  var
    tee : char;
    sas : boolean;
  begin
     sas := false;
   repeat
      clrscr;
      writeln('******* Menu General *********');
      writeln;
      writeln('   1 = INCLUIR');
      writeln('   2 = CONSULTAR');
      writeln('   3 = MODIFICAR');
      writeln('   4 = ELIMINAR');
      writeln('   5 = ORDENAR');
      writeln('   6 = CONTADOR');
      writeln('   7 = SALIR');
      writeln;
      writeln('<<<<< Elija Opcion >>>>>');
      repeat
         tee := readkey;
      until tee in[#49..#55];
  case tee of
 #49 : begin
         clrscr;
         cont := cont + 1;
         if cont > perso then
         cont := perso;
         incluir;
        ordenarregistro;
        end;
 #50 : begin
          clrscr;
          write('   Entre Numero de pasaporte : ');
          readln(coven);
          consultar(coven);
       end;
 #51 : begin
          clrscr;
          write('   Entre Numero de pasaporte : ');
          readln(coven);
          modificar(coven);
       end;
 #52 : begin
          clrscr;
          write('   Entre Numero de pasaporte : ');
          readln(coven);
          eliminar(coven);
       end;
 
 #53 : begin
          clrscr;
          mostraresultados;
       end;
 
 #54 : begin clrscr; contadores; end;
 
 #55 : sas := true;
   end;
   until sas = true;
  end;
 
 
   begin
       cont := 0;
       menu;
   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
sin imagen de perfil

Ordenamiento de registros

Publicado por crack81 (58 intervenciones) el 08/01/2016 01:25:06
Me alegra que allas dado con tu solucion saludos que para eso estamos todos los que participamos en la comunidad
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