;; make sure t 'contains' everything in l. ;; this returns a list of the elements #t if the ;; element is in the tree and the element number ;; if the element is missing. (define (check-contents t l) (map (lambda (val) (if (contains t val) #t val ) ) l ) ) ;; this prints out a message followed by an object value. (define (print message value) (display "; ") (display message) (write value) (newline) ) ;; initial elements to add to tree. (define el '(11 5 2 7 15 13 19)) ;; create complete tree: ;; 11 ;; 5 15 ;; 2 7 13 19 (define t (tree-add-list '() el)) (newline) (newline) ;; make sure t contains everything. (display ";; make sure t contains everything ") (display "-- this checks add.\n") (print "el => " el) (print "t => " t) (print "(check-contents t el) => " (check-contents t el)) (newline) ;; delete 13. (define t-13 (delete t 13)) (check-contents t-13 el) (display ";; remove 13 from t ") (display "-- this checks delete on a leaf\n") (print "t-13 => " t-13) (print "(check-contents t-13 el) => " (check-contents t-13 el)) (newline) ;; delete 15 (in addition to 13) (define t-13-15 (delete t-13 15)) (display ";; remove 13 from t-15 ") (display "-- this checks delete on a node with only one child\n") (print "t-13-15 => " t-13-15) (print "(check-contents t-13-15 el) => " (check-contents t-13-15 el)) (newline) ;; delete 5 (from original tree) (define t-5 (delete t 5)) (display ";; remove 5 from t ") (display "-- this checks delete on a node with two children\n") (print "t-5 => " t-5) (print "(check-contents t-5 el) => " (check-contents t-5 el)) (newline) ;; delete 11 (root) from original tree (define t-11 (delete t 11)) (display ";; remove 11 from t ") (display "-- this checks delete of root\n") (print "t-11 => " t-11) (print "(check-contents t-11 el) => " (check-contents t-11 el)) (newline) ;; see if t contains any old element that is not in t. (display ";; check to see if t contains 99\n") (print "(contains t 99) => " (contains t 99)) ;; by now, we should be pretty convinced ;; that all of the tree functions work. (newline) (newline)