Re[2]: [Haskell-cafe] inserting values in a binary tree

2008-05-09 Thread Bulat Ziganshin
Hello PR, Saturday, May 10, 2008, 3:10:59 AM, you wrote: > in C you'd fiddle with pointers and Bob's your uncle. Here I'm not > sure how to piece that tree back together again with the new element > after having expanded it recursively. in Haskell, you just return new tree with element inserted

Re: [Haskell-cafe] inserting values in a binary tree

2008-05-09 Thread PR Stanley
Are there any invariants you wish to maintain when inserting? If not, it's rather trivial. Paul: The idea is to find a value in the tree greater than the new value and then placing the new value before it on the tree. duplicates are ignored and if no value greater than he new value

Re: [Haskell-cafe] inserting values in a binary tree

2008-05-09 Thread Lennart Augustsson
Are there any invariants you wish to maintain when inserting? If not, it's rather trivial. -- Lennart On Fri, May 9, 2008 at 11:35 PM, PR Stanley <[EMAIL PROTECTED]> 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 sear

Re: [Haskell-cafe] inserting values in a binary tree

2008-05-09 Thread Thomas Davie
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 in

[Haskell-cafe] inserting values in a binary tree

2008-05-09 Thread PR Stanley
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? Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/list