procedure OrdeneExterno;
const OrdemIntercalConst = 2;
var NBlocos	  : integer;
   ArqEntrada	  : ArqEntradaTipo;
   ArqSaida	  : ArqEntradaTipo;
   ArrArqEnt	  : array[1..OrdemIntercalConst] of ArqEntradaTipo;
   Fim		  : boolean;
   Low, High, Lim : integer;
begin
   NBlocos := 0;
   ArqEntrada := Arquivo a ser ordenado;
   repeat {Formacao inicial dos NBlocos ordenados }
      NBlocos := NBlocos + 1;
      Fim := EnchePaginas(NBlocos,ArqEntrada);
      OrdeneInterno;
      ArqSaida := AbreArqSaida(NBlocos);
      DescarregaPaginas(ArqSaida);
      Close(ArqSaida);
   until Fim;
   Close(ArqEntrada);
   Low  :=1;
   High := NBlocos;
   while Low < High do {Intercalacao dos NBlocos ordenados}
    begin
       Lim := Minimo(Low +OrdemIntercalConst-1, High);
       AbreArqEntrada(ArrArqEnt, Low, Lim);
       High := High + 1;
       ArqSaida := AbreArqSaida(High);
       Intercale(ArrArqEnt, Low, Lim, ArqSaida);
       Close(ArqSaida);
       for i:= Low to Lim do
         begin
	 Close(ArrArqEnt[i]);
	 Erase(ArrArqEnt[i]);
	 end;
       Low := Low + OrdemIntercalConst;
    end;
   Dar Rename no arquivo High para nome fornecido pelo usuario;
end;
      
