I am trying to add a new node to the tree. The following are my definitions and function type:
(define-struct (Some T)
([value : T]))
(define-type (Option T)
(U 'None (Some T)))
(define-type BST (U 'E Nd))
(define-struct Nd
([root : Integer]
[lsub : BST]
[rsub : BST]))
(: insert : Integer BST -> BST)
;; insert an item into a tree
;; note: do not insert duplicate items
(define (insert n x)
(match x
('E 'E)
((Nd ro ls rs)
(cond
((= (size x) 1) (Nd ro (Nd n 'E 'E) 'E))
(else
(Nd ro ls rs))))))
Insert is the insert that will insert the node into the tree.
The following is the command that I will give:
(insert 10 (Nd 1 (Nd 2 (Nd 4 'E 'E) (Nd 5 'E 'E)) (Nd 3 (Nd 6 'E 'E) (Nd 7 'E 'E))))
And it should insert ten into the tree. However, I am learning independently at home and I have NO idea what to do. Please help. Thank you so much!