問題2.61

(define (element-of-set? x set)
  (cond ((null? set) #f)
        ((= x (car set)) #t)
        ((< x (car set)) #f)
        (else (element-of-set? x (cdr set)))))

(define (intersection-set set1 set2)
  (if (or (null? set1) (null? set2)) '()
      (let ((x1 (car set1)) (x2 (car set2)))
        (cond ((= x1 x2)
               (cons x1
                     (intersection-set (cdr set1)
                                       (cdr set2))))
              ((< x1 x2)
               (intersection-set (cdr set1) set2))
              ((< x2 x1)
               (intersection-set set1 (cdr set2)))))))

(define (adjoin-set x set)
  (define (iter x items product)
    (cond ((null? items) (append product (list x)))
          ((= x (car items)) set)
          ((< x (car items)) (append product (cons x items)))
          (else (iter x (cdr items) 
                      (append product (list (car items)))))))
  (iter x set '()))

(adjoin-set 3 (adjoin-set 5 '(1 2 4 6)))
;->( 1 2 3 4 5 6 )