Code Review
Compare your solutions
(define (union-set-ordered set1 set2)
(cond ((null? set1) set2)
((null? set2) set1)
(else (let ((x1 (car set1)) (x2 (car set2)))
(cond ((= x1 x2) (cons x1 (union-set-ordered (cdr set1) (cdr set2))))
((< x1 x2) (cons x1 (union-set-ordered (cdr set1) set2)))
((> x1 x2) (cons x2 (union-set-ordered set1 (cdr set2)))
))
))
)
)
(define (intersection-set-ordered set1 set2)
(if (or (null? set1) (null? set2))
'()
(let ((x1 (car set1)) (x2 (car set2)))
(cond ((= x1 x2)
(cons x1 (intersection-set-ordered (cdr set1)
(cdr set2))))
((< x1 x2)
(intersection-set-ordered (cdr set1) set2))
((< x2 x1)
(intersection-set-ordered set1 (cdr set2)))))))
(define (union-set set1 set2)
(list->tree (union-set-ordered (tree->list-2 set1) (tree->list-2 set2)))
)
(define (intersection-set set1 set2)
(list->tree (intersection-set-ordered (tree->list-2 set1) (tree->list-2 set2)))
)
#| END |#