Revision: 63440
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 8, 2013 13:29 by MauricioM
Initial Code
{
EJERCICIO 33 - PSEUDOCODIGO
Algoritmo selección
INICIO
Leer V1, M, N
Desde (J=1 hasta N) hacer
MENOR <-- 1
Desde (I= 1 hasta N) hacer
Si (V1(I) < V1(MENOR))
Entonces MENOR <-- I
Fin si
Fin desde
V2(J) <-- 1(MENOR)
V1(MENOR) <-- M
Fin desde
Mostrar V2
FIN
}
Program seleccion(output);
var
{ Se declaran las variables que se utilizaran en el programa }
v1, v2 : array[1..10] of integer;
m, n, j, i, menor : integer;
begin
{
Completamos el array (vector) con algunos datos arbitrarios
Las próximas lineas son equivalentes a Equivalente a Leer V1, M, N
}
v1[1] := 20;
v1[2] := 50;
v1[3] := 150;
v1[4] := 25;
v1[5] := 70;
v1[6] := 1;
v1[7] := -40; { Podemos usar valores negativos }
v1[8] := 33;
v1[9] := 5;
v1[10] := 700;
m:= 9999; { Sabemos que el array no contienen un valor superior a 9999 }
n:= 10; { Cantidad de elementos que tiene el array }
{ Desde (J=1 hasta N) hacer }
for j := 1 to n do
begin
menor := 1;
{ Desde (I= 1 hasta N) hacer }
for i := 1 to n do
begin
if v1[i] < v1[menor] then
begin
menor := i;
end;
end;
{ Fin desde }
v2[j] := v1[menor];
v1[menor] := m;
end;
{ Fin desde }
{
Mostrar v2 - Simplemente iteramos el vector para mostrar los valores
en las posiciones del 1 al 10.
}
writeln('Veamos si los elementos en v2 estan ordenados...');
for i := 1 to n do
writeln(v2[i]);
end.
Initial URL
Initial Description
Técnicas de Programación. Ejercicio 33 - Algoritmo selección (usando un array auxiliar)
Initial Title
Ejercicio 33 - Algoritmo ordenamiento
Initial Tags
order
Initial Language
Pascal