How can I implement a function to delete an element in a binary search tree?
This is my tree:
data Tree a = Leaf
| Node a (Tree a) (Tree a)
I know that in case my tree is a Leaf
delete :: (Ord a) => a -> Tree a -> Tree a
delete _ Leaf = Leaf
and in case left and right are not empty, I have to delete the minimum from right (or maximum from left) and it became the root. But, how can I implement it??
You should implement a function
that deletes the minimum element from a tree and returns both the modified tree and the minimum element. Then the deletion algorithm becomes: find the node with the item to be deleted and call