Pascal/Turbo Pascal - hola nesecito ayuda con este codigo

 
Vista:
sin imagen de perfil

hola nesecito ayuda con este codigo

Publicado por Matias Paz (2 intervenciones) el 09/03/2016 22:34:13
este codigo lo saque de un libro que estoy estudiando es el metodo de ordenacion rapido(quickSort) pero no funciona da unos resultados rarisimos...

program Rapido;
uses
crt;
const n = 5;
type indice = 0..n;
type item = record
clave:integer;
end;
type at = array[indice] of item;
procedure rellenar(var a:at);
var
i:indice;
begin
randomize;
for i := low(a) to high(a) do
a[i].clave:=random(9)+1;
end;
procedure rapido1(var a:at);
const m = 12;
var
i,j,iz,de:indice;
x,w:item;
p:0..m;
pila:array[1..m] of record
iz,de:indice
end;
begin
p:=1;
pila[1].iz:=1;
pila[1].de:=m;
repeat
iz:=pila[p].iz;
de:=pila[p].de;
p:=p-1;
repeat
i:=iz;
j:=de;
x:=a[(iz-de) div 2];
repeat
while a[i].clave < x.clave do
i:=i-1;
while x.clave < a[j].clave do
j:=j-1;
if i <= j then
begin
w:=a[i];
a[i]:=a[j];
a[j]:=w;
i:=i-1;
j:=j-1;
end;
until i > j;
if j < de then
begin
p:=p-1;
pila[p].iz:=i;
pila[p].de:=de;
end;
de:=j;
until iz >= de;
until p = 0;
end;
procedure mostrar(a:at);
var
i:indice;
begin
for i:= low(a) to high(a) do
begin
write(a[i].clave,' ');
end;
writeln();
end;
var
lista:at;
begin
rellenar(lista);
mostrar(lista);
rapido1(lista);
mostrar(lista);
readln();
end.

asi esta en el libro mas o menos porque para que compile le agregue los metodos 'rellenar', 'mostrar'
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

hola nesecito ayuda con este codigo

Publicado por ramon (2158 intervenciones) el 10/03/2016 16:33:36
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
{Mira esto}
 
program Rapido;
uses
crt;
const n = 5;
type
   indice = 0..n;
  item = record
        clave:integer;
        end;
   at = array[indice] of item;
  var
   lista:at;
 
   procedure rellenar(var a:at);
   var
     i:indice;
    begin
      fillchar(a,sizeof(a),0);
     randomize;
       for i := low(a) to high(a) do
       begin
        a[i].clave:=random(9)+1;
       end;
    end;
 
    procedure rapido1(var a:at);
    const
       m = 5;
    var
      p, t : integer;
      w : item;
    begin
       fillchar(w,sizeof(w),0);
       for p := 0 to high(indice) do
         for t := high(indice) downto p + 1 do
         if a[p].clave > a[t].clave then
         begin
            w.clave := a[p].clave;
            a[p].clave := a[t].clave;
            a[t].clave := w.clave;
         end;
    end;
 
    procedure mostrar(a:at);
    var
      i:indice;
      begin
        for i:= low(indice) to high(indice) do
        begin
          write(a[i].clave,' ');
        end;
        writeln;
     end;
 
begin
      clrscr;
      rellenar(lista);
      mostrar(lista);
      writeln;
      rapido1(lista);
      mostrar(lista);
      readln;
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

hola nesecito ayuda con este codigo

Publicado por Matias (2 intervenciones) el 13/03/2016 11:03:36
Hola Ramon Muchisimas Gracias yo no tengo idea de porque en el libro esta escrito de esta manera pero seguire investigando y tu codigo funciona muy bien muchas gracias
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