given a tree of the type:
data THuffman = Hoja Char | Nodo THuffman THuffman
and with the data type
type TablaCodigo = [(Char,String)]
I must create a function
extraerCodigos :: THuffman -> TablaCodigo
That I generate a table of codes from a huffman tree. So far I have the recursive part of the function, but I can not figure out how to generate the string code.
The code would be: 1 if it is a node on the right and 0 if it is a node on the left. In the part of Char in the tuple, would go the data of the Leaf of the tree (that is a char)
Here goes what codee so far (the main function works the helper does not give desired result)
extraerCodigos (Hoja x) = [(x,"0")]
extraerCodigos (Nodo (Hoja x) (Hoja y)) = [(x,enumC "0"),(y,enumC "1")]
extraerCodigos (Nodo (Hoja x) y) = (x,enumC "0") : (extraerCodigos y)
extraerCodigos (Nodo x (Hoja y)) = (y, enumC "1") : (extraerCodigos x)
extraerCodigos (Nodo x y) = (extraerCodigos x) ++ (extraerCodigos y)
enumC bin = if (tail bin) == "0" then bin ++ "0"
else bin ++ "1"