Constructing a binary tree from a postorder visit

Nuno Santos developer at imaginando.net
Wed May 24 09:08:57 EDT 2006


Hi,

I have this datatype:

data PeAux a = Folha Char | Nodo Char (PeAux a) (PeAux a)  deriving Show


And i need to reconstruct a tree from its post order visit....  
example "12H3V"

|'m trying something like this to create the nodes and leave what lefts:


converteAux [] (x,y) = (x,y)
converteAux (a:t) (x,y)
         | ((length (a:t))<3) = converteAux [] (x,y ++ (a:t))
converteAux (a:b:t) (x,y)
         | ((length (a:b:t))<3) = converteAux [] (x,y ++ (a:b:t))
converteAux (a:b:c:t) (x,y)
         | (isNumber a) && (isNumber b) && (isLetter c) = converteAux  
t (x ++ [(Nodo c (Folha a) (Folha b))],y)
         | otherwise = converteAux (b:c:t) (x,y++[a])


and i'm trying this to rebuild the tree but i dont know what to do in  
the case of [] since i dont have a empty constructer


preenche (x:xs) = Nodo 'H' (preenche xs) x


Can anyone help me?

Many thx,

Nuno



More information about the Glasgow-haskell-users mailing list