-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree-map.scm
26 lines (22 loc) · 960 Bytes
/
tree-map.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
;;;Coursework 2
;;;Question 2
;;;by Anish Katariya(ak7n14@soton.ac.uk)
;;;
;;;Solution:
(load "tree-implementation-list.scm")
(load "tree-equal.scm")
(define tree-map
(lambda (fun tree)
(cond((null? tree) '())
((node? tree) (make-node (fun (tree-labels tree))
(tree-map fun (node-left tree)) (tree-map fun(node-right tree))))
((leaf? tree) (make-leaf (fun (tree-labels tree)))))))
(define remove-labels
(lambda (labels tree)
(tree-map (lambda(set)(set-minus set labels))tree)))
;;;For the 1st function the function takes in another function and a tree
;;;It then makes a new tree by traversing the given tree and copying the
;;;The value of the label after applying the function to it
;;;For the 2nd function I take in the set of labels to be removed
;;;And the tree. I then call the tree-map function and passing in the function
;;;as set-minus of the label of the tree and the list of labels