[Haskell-cafe] inserting values in a binary tree

Thomas Davie tom.davie at gmail.com
Fri May 9 18:40:29 EDT 2008

On 10 May 2008, at 00:35, PR Stanley wrote:

> Hi
> data Ord a => Tree a = Nil | Node (Tree a) a (Tree a)
> How would one go about inserting a value in a binary search tree of  
> the above description?

All you need to do is consider what the trees should look like in the  
two cases:

If I try and insert an item into a completely empty tree, what do I  
end up with?  I'll give you a hint, it has one Node, and 2 Nils.
If I have a Node, do I need to insert into the left tree, or the right  

Take it from there


More information about the Haskell-Cafe mailing list