Ordena de manera ascendente el contenido de un vector
pascal:
{-Victor De la Rocha}
{-Algoritmia@groups.msn.com}
{-www.myalgorithm.com}
uses
crt;
type
vector=array [1..100] of integer;
var
arreglo:vector;
cantidad,cont1,cont2,temp1,temp2,numero:integer;
begin
ClrScr;
Write('Cantidad de valores: ');Readln(cantidad);
writeln;
for cont1:=1 to cantidad do
begin
Write('Valor ',cont1,': ');Readln(arreglo[cont1]);
end;
writeln;
for cont1:=cantidad downto 1 do
begin
for cont2:=1 to cont1 do
begin
if arreglo[cont1]<arreglo[cont2] then
begin
temp1:=arreglo[cont1];
temp2:=arreglo[cont2];
arreglo[cont1]:=temp2;
arreglo[cont2]:=temp1;
end;
end;
end;
for cont1:=1 to cantidad do
begin
if cont1=cantidad then
begin
write(arreglo[cont1],'.');
end
else
begin
write(arreglo[cont1],', ');
end;
end;
ReadKey;
end.
{-Algoritmia@groups.msn.com}
{-www.myalgorithm.com}
uses
crt;
type
vector=array [1..100] of integer;
var
arreglo:vector;
cantidad,cont1,cont2,temp1,temp2,numero:integer;
begin
ClrScr;
Write('Cantidad de valores: ');Readln(cantidad);
writeln;
for cont1:=1 to cantidad do
begin
Write('Valor ',cont1,': ');Readln(arreglo[cont1]);
end;
writeln;
for cont1:=cantidad downto 1 do
begin
for cont2:=1 to cont1 do
begin
if arreglo[cont1]<arreglo[cont2] then
begin
temp1:=arreglo[cont1];
temp2:=arreglo[cont2];
arreglo[cont1]:=temp2;
arreglo[cont2]:=temp1;
end;
end;
end;
for cont1:=1 to cantidad do
begin
if cont1=cantidad then
begin
write(arreglo[cont1],'.');
end
else
begin
write(arreglo[cont1],', ');
end;
end;
ReadKey;
end.
Cantidad: 35 Valor 1: 40 Valor 2: 18 Valor 3: 60 Valor 4: 36 Valor 5: 55 Valor 6: 91 Valor 7: 36 Valor 8: 33 Valor 9: 10 Valor 10: 71 Valor 11: 57 Valor 12: 48 Valor 13: 2 Valor 14: 16 Valor 15: 96 Valor 16: 14 Valor 17: 80 Valor 18: 38 Valor 19: 72 Valor 20: 18 Valor 21: 37 Valor 22: 95 Valor 23: 60 Valor 24: 93 Valor 25: 23 Valor 26: 96 Valor 27: 81 Valor 28: 22 Valor 29: 33 Valor 30: 0 Valor 31: 5 Valor 32: 41 Valor 33: 15 Valor 34: 17 Valor 35: 57 Vector ordenado ascendentemente Valor 1: 2 Valor 2: 5 Valor 3: 10 Valor 4: 14 Valor 5: 15 Valor 6: 16 Valor 7: 17 Valor 8: 18 Valor 9: 18 Valor 10: 22 Valor 11: 23 Valor 12: 33 Valor 13: 33 Valor 14: 36 Valor 15: 36 Valor 16: 37 Valor 17: 38 Valor 18: 40 Valor 19: 41 Valor 20: 48 Valor 21: 55 Valor 22: 57 Valor 23: 57 Valor 24: 60 Valor 25: 60 Valor 26: 71 Valor 27: 72 Valor 28: 80 Valor 29: 81 Valor 30: 91 Valor 31: 93 Valor 32: 95 Valor 33: 96 Valor 34: 96