Pascal/Turbo Pascal - ayuda de metodos de busqueda y ordenacion

 
Vista:

ayuda de metodos de busqueda y ordenacion

Publicado por mauro (1 intervención) el 19/07/2013 03:39:06
hola que tal,queria saber si me pueden facilitar los algoritmos de metodos de busqueda: secuencial,binaria,maximo y minimo(ramificacion del arbol, campeonato,prepo) y busqueda externa.

y otro pedido respecto a los algoritmos de ordenacion: burbuja,seleccion,baraja,quick sort,shell sork.

muchas gracias,espero su contestacion favorable
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 de metodos de busqueda y ordenacion

Publicado por ramon (2158 intervenciones) el 22/07/2013 21:54:28
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
{A ver si esto te ayuda}
 
 program busqueda;
 uses
    crt;
  type
     integerarray = array[1..100] of integer;
 
  var
    t : integerarray;
    c, y, x : integer;
 
  procedure intercambio(var q, s : integer);
  var
     ex : integer;
     begin
       if q <> s then
       begin
          ex := q;
          q := s;
          s := ex;
       end;
    end;
 
  procedure ordenacion_burbuja(nu : integer);
  var
     a, d : integer;
  begin
      for a := 2 to nu do
       for d := nu downto a do
       if t[d - 1] > t[d] then
       intercambio(t[d],t[d - 1]);
  end;
 
  procedure prueva_burbuja;
  begin
     randomize;
     clrscr;
     for x := 1 to 100 do
     t[x] := random(100) + 1;
     x := 0;
     ordenacion_burbuja(100);
     writeln('**** Ordenacion Burbuja ****');
     writeln;
     for x := 1 to 100 do
     write('   ',t[x]);
     readkey;
  end;
 
 
    procedure parcial(i, d : integer; var f : integerarray);
    var
      p, l, r, y, k, v : integer;
     begin
        v := (f[i] + f[d]) div 2;
        y := i;
        k := d;
    repeat
        while f[y] < v do
        y := y + 1;
        while v < f[k] do
        k := k - 1;
        if y <= k then
        begin
            intercambio(f[y],f[k]);
            y := y + 1;
            k := k - 1;
        end;
     until y > k;
  if i < k then
  parcial(i,k,f);
  if y < d then
  parcial(y,d,f);
 end;
 
 
   procedure prueva_rapida;
   begin
      clrscr;
      for x := 1 to 100 do
      t[x] := random(100) + 1;
      parcial(1,100,t);
      writeln('**** Ordenacion Rapida ****');
      writeln;
      for y := 1 to 100 do
      write('   ',t[y]);
      readkey;
   end;
 
  procedure ordena_shell(nu : integer);
  var
    tem, i1, j1, k1, x1 : integer;
  begin
     tem := nu div 2;
   repeat
       for i1 := (tem + 1) to nu do
       begin
          j1 := i1 - tem;
        repeat
            k1 := j1 + tem;
            if t[j1] <= t[k1] then
            j1 := 0
         else
            begin
               intercambio(t[j1],t[k1]);
               j1 := j1 - tem;
            end;
        until j1 <= 0;
       end;
        tem := tem div 2;
   until tem <= 0;
  end;
 
  procedure prueva_shell;
  begin
     randomize;
     clrscr;
     for x := 1 to 100 do
     t[x] := random(100) + 1;
     ordena_shell(100);
     writeln('**** Ordenacion Shell ****');
     writeln;
     for x := 1 to 100 do
     write('   ',t[x]);
     readkey;
  end;
 
  procedure ordena_intercambio;
  var
    xtp : integer;
  begin
     randomize;
     clrscr;
     for x := 1 to 100 do
     t[x] := random(100) + 1;
     for x := 1 to 100 do
       for y := x + 1 to 100 do
       if t[x] > t[y] then
       begin
          xtp := t[x];
          t[x] := t[y];
          t[y] := xtp;
       end;
     writeln('**** Ordenacion Intercambio ****');
     writeln;
     for x := 1 to 100 do
     write('   ',t[x]);
     readkey;
  end;
 
  procedure ordena_seleccion;
  var
    aux, meno, ip, jp : integer;
  begin
     for ip := 1 to 100 do
     meno := t[ip];
      for jp := ip + 1 to 100 do
         if t[jp] < meno then
         meno := jp;
         if t[ip] <> meno then
         begin
             aux := t[ip];
             t[ip] := t[meno];
             t[meno] := aux;
         end;
     end;
 
  procedure prueva_seleccion;
  begin
     clrscr;
     for x := 1 to 100 do
     t[x] := random(100) + 1;
     ordena_seleccion;
     for x := 1 to 100 do
     write('   ',t[x]);
     readkey;
  end;
 
 
  function metodo_secuencial(num, asta : integer) : integer;
  var
    encontra : boolean;
  begin
     encontra := false;
     for y := 1 to asta do
     if num = t[y] then
     begin
        metodo_secuencial := y;
        encontra := true;
        break;
     end;
     if encontra = false then
     metodo_secuencial := 0;
  end;
 
  procedure prueva_secuencial;
  begin
     randomize;
     clrscr;
     for x := 1 to 100 do
     t[x] := random(100) + 1;
     parcial(1,100,t);
     x := 0;
       write('   Introduzca El Numero A Buscar : ');
       readln(x);
       writeln('**** Busqueda Secuencial ****');
       writeln;
       for c := 1 to 100 do
       write('   ',t[c]);
       writeln;
       c := 0;
       c := metodo_secuencial(x,100);
       if c = 0 then
       writeln('El Numero No Esta')
     else
       writeln('El Numero Si Esta : ',t[c]);
     readkey;
  end;
 
  function metodo_binaria(num, asta : integer) : integer;
  var
     l, b, m : integer;
  begin
      b := 1;
      l := asta;
    repeat
       m := trunc((l + b) div 2);
       if num > t[m] then
       b := m + 1
    else
       if num < t[m] then
       l := m - 1
    else
       l := - 1;
   until l <= b;
   if l = - 1 then
   metodo_binaria := m
 else
   metodo_binaria := 0;
  end;
 
  procedure prueva_binaria;
  begin
     randomize;
     clrscr;
     for x := 1 to 100 do
     t[x] := random(100) + 1;
     parcial(1,100,t);
     x := 0;
       write('   Introduzca El Numero A Buscar : ');
       readln(x);
       writeln('**** Busqueda Binaria ****');
       writeln;
       for c := 1 to 100 do
       write('   ',t[c]);
       writeln;
       c := 0;
       c := metodo_binaria(x,100);
       if c = 0 then
       writeln(' El Numero No Esta')
     else
       writeln(' El Numero Si Esta : ',t[c]);
       readkey;
  end;
 
  procedure metodo_maximo;
  begin
     randomize;
     clrscr;
     for x := 1 to 100 do
     t[x] := random(100) + 1;
     parcial(1,100,t);
     writeln('**** Busqueda Maximo ****');
     writeln;
     writeln(' El Maximo Es : ',t[100]);
     readkey;
  end;
 
  procedure metodo_minimo;
  begin
     randomize;
     clrscr;
     for x := 1 to 100 do
     t[x] := random(100) + 1;
     parcial(1,100,t);
     writeln('**** Busqueda Minimo ****');
     writeln;
     writeln(' El Minimo Es : ',t[1]);
     readln;
  end;
 
  procedure menu;
  var
    sal : boolean;
    tecla : char;
  begin
     sal := false;
   repeat
      clrscr;
      writeln('             ***** Menu General *****');
      writeln;
      writeln('     1 : Ordenacion Burbuja ');
      writeln('     2 : Ordenacion Rapida (quicksort)');
      writeln('     3 : Ordenacion Shell ');
      writeln('     4 : Ordenacion Intercambio ');
      writeln('     5 : Ordenacion Seleccion ');
      writeln('     6 : Busqueda Secuencial ');
      writeln('     7 : Busqueda Binaria ');
      writeln('     8 : Valor Maximo ');
      writeln('     9 : Valor Minimo ');
      writeln('     0 : Salir ');
      writeln;
      writeln('             <<<<< Eleja Opcion >>>>> ');
      repeat
         tecla := readkey;
      until tecla in['0','1','2','3','4','5','6','7','8','9'];
   case tecla of
 '1' : prueva_burbuja;
 '2' : prueva_rapida;
 '3' : prueva_shell;
 '4' : ordena_intercambio;
 '5' : prueva_seleccion;
 '6' : prueva_secuencial;
 '7' : prueva_binaria;
 '8' : metodo_maximo;
 '9' : metodo_minimo;
 '0' : sal := true;
   end;
   until sal = true;
  end;
 
  begin
     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