Mrs Senora Ada Nev, a descendant of the (in)famous Ada Lovelace and an AP/CS teacher in the wild, wild west, has finally understood trees. Here is her data definition:
(define-struct two (left center right)) (define-struct thr (left up down right)) ;; A 2-3-Tree is one of: ;; -- a Number ;; -- (make-two 2-3-Tree Number 2-3-Tree) ;; -- (make-thr 2-3-Tree Number Number 2-3-Tree)
Now she wants you to create a template for functions that process 2-3-Trees:
;; ff : 2-3-Tree -> ??? ;; to do something with a 2-3-Tree
Solution:
Grader: Richard
;; [PTS: 5
;; -- 1 for 3 correct cond clauses
;; -- 2 4/5 correctly used selectors
;; -- 2 for 4 correct natural recursions]
(define (ff t23)
(cond
[(number? t23) ...]
[(two? t23)
... (ff (two-left t23)) ...
... (two-center t23) ...
... (ff (two-right t23))]
[(thr? t23)
... (ff (thr-left t23)) ...
... (thr-up t23) ...
... (thr-up t23) ...
... (ff (thr-right t23))]))