Could anyone please help me with my assignment questions? I've done most of it but I'm still stuck on these 3 questions.
Here is the question:
Consider the following types of search trees and balanced trees
data STree = Leaf | Node STree Int STree data Btree = Tip Int | Branch Btree Btree
whose constructors are subject to the following constraints:
- Values of the form
Node left n right
must have all integers in left being at mostn
and all integers in right being greater thann
.- Values of the form
Branch left right
must have a difference between the numbers of integers inleft
andright
of at most one.a) Define a recursive function
stree :: [Int] -> STree
that constructs a search tree from a list of integers.b) Define a recursive function
btree :: [Int] -> BTree
that constructs a balanced tree from a non-empty list of integers.c) Using merge, define a recursive function
collapse :: BTree -> [Int]
that collapses a balanced tree to give a sorted list of integers.
Please help me!!!
Thanks very much in advance!