Code Review

Compare your solutions

    #| BEGIN (Write your solution here) |#
; Code from the book
(define (intersection-set-ol set1 set2)
(if (or (null? set1) (null? set2))
'()
(let ((x1 (car set1)) (x2 (car set2)))
(cond ((= x1 x2)
(cons x1 (intersection-set-ol (cdr set1)
(cdr set2))))
((< x1 x2)
(intersection-set-ol (cdr set1) set2))
((< x2 x1)
(intersection-set-ol set1 (cdr set2)))))))

; Code from previous exercise
(define (union-set-ol s1 s2)
    (cond
        ((null? s1) s2)
        ((null? s2) s1)
        ((= (car s1) (car s2)) (cons (car s1) (union-set-ol (cdr s1) (cdr s2))))
        ((< (car s1) (car s2)) (cons (car s1) (union-set-ol (cdr s1) s2)))
        (else (cons (car s2) (union-set-ol s1 (cdr s2))))
    )
)

; My code
(define (union-set s1 s2)
    (let ((s1-ol (tree->list-2 s1)) (s2-ol (tree->list-2 s2)))
        (list->tree (union-set-ol s1-ol s2-ol))
    )
)
(define (intersection-set s1 s2)
    (let ((s1-ol (tree->list-2 s1)) (s2-ol (tree->list-2 s2)))
        (list->tree (intersection-set-ol s1-ol s2-ol))
    )
)
#| END |#