Code Review
Compare your solutions
#| BEGIN (Write your solution here) |#
(define (left-branch tree) (car tree))
(define (right-branch tree) (cadr tree))
(define (element-of-set? x set)
(cond ((null? set) #f)
((eq? x (car set)) #t)
(else (element-of-set? x (cdr set)))))
(define (correct-branch? symb branch)
(element-of-set? symb (symbols branch))
)
(define (encode-symbol symb tree)
(if (leaf? tree) '()
(cond ((correct-branch? symb (left-branch tree)) (cons '0 (encode-symbol symb (left-branch tree))))
((correct-branch? symb (right-branch tree)) (cons '1 (encode-symbol symb (right-branch tree))))
(else (error "cannot find symbol = " symb))
)
)
)
#| END |#