Procedure OrdenarA(var A:LEnteros;n:byte); Procedure ContarPosicionar(A,B:LEnteros;i:longint); Var j:longint; d:byte; pos:array [0..255] of longword; //para contar y obtener las posiciones Begin FillDWord(pos,256,0); //reinicia a 0 for j:=low(A) to high(A) do Begin //permite obtener el byte d:=(A[j] shr ((8*i)-8)) and $FF; //contador pos[d]:=pos[d]+1 End; // acumula las cuentas para obtener las posiciones for j:=0 to 254 do pos[j+1]:=pos[j]+pos[j+1]; for j:=high(A) downto low(A) do //ascendente Begin //permite obtener el byte para ubicarlo en la posicion correcta d:=(A[j] shr ((8*i)-8)) and $FF; pos[d]:=pos[d]-1; //se decrementa la posicion B[pos[d]]:=A[j]; //se coloca en nueva posicion End; End; Var i:longint; B:LNaturales; // arreglo dinamico auxiliar Begin SetLength(B,Length(A)); if (n=1) then for i:=low(A) to high(A) do A[i]:=A[i]+(-128); if (n=2) then for i:=low(A) to high(A) do A[i]:=A[i]+(-32768); if (n=3) then for i:=low(A) to high(A) do A[i]:=A[i]+(-8388608); if (n=4) then for i:=low(A) to high(A) do A[i]:=A[i]+(-2147483648); if (n=5) then for i:=low(A) to high(A) do A[i]:=A[i]+(-549755813888); if (n=6) then for i:=low(A) to high(A) do A[i]:=A[i]+(-140737488355328); if (n=7) then for i:=low(A) to high(A) do A[i]:=A[i]+(-36028797018963968); if (n=8) then for i:=low(A) to high(A) do A[i]:=A[i]+(-9223372036854775808); for i:=1 to n do if (i mod 2)<>0 then ContarPosicionar(A,B,i) //se colocarán en B else ContarPosicionar(B,A,i); //se colocarán en A if not(n mod 2)<>0 then for i:=low(A) to high(A) do A[i]:=B[i]; if (n=1) then for i:=low(A) to high(A) do A[i]:=A[i]-(-128); if (n=2) then for i:=low(A) to high(A) do A[i]:=A[i]-(-32768); if (n=3) then for i:=low(A) to high(A) do A[i]:=A[i]-(-8388608); if (n=4) then for i:=low(A) to high(A) do A[i]:=A[i]-(-2147483648); if (n=5) then for i:=low(A) to high(A) do A[i]:=A[i]-(-549755813888); if (n=6) then for i:=low(A) to high(A) do A[i]:=A[i]-(-140737488355328); if (n=7) then for i:=low(A) to high(A) do A[i]:=A[i]-(-36028797018963968); if (n=8) then for i:=low(A) to high(A) do A[i]:=A[i]-(-9223372036854775808); End;