%%%
%%% Authors and Copyright:
%%%   Christian Schulte <schulte@imit.kth.se>
%%%
%%% Last change:
%%%   $Date: 2002/10/03 07:58:50 $ by $Author: schulte $
%%%   $Revision: 1.1 $
%%%

local
   fun {Scan Hs I Ir}
      %% Hs is the list of Huffman trees
      %% I is the tree with so-far lowest frequency
      %% Ir are all trees already scanned and known
      %% to have higher frequency than I
      case Hs
      of nil then I#Ir
      [] H|Hr then
         if {Frequency H}<{Frequency I} then
            %% Lower frequency tree!
            {Scan Hr H I|Ir}
         else
            {Scan Hr I H|Ir}
         end
      end
   end
in
   fun {FindLowest Hs}
      {Scan Hs.2 Hs.1 nil}
   end
end