2.28

练习 2.28 写一个过程fringe,它以一棵树(表示为表)为参数,返回一个表,表中的元素是这棵树的所有树叶,按照从左到右的顺序。例如:

(define x (list (list 1 2) (list 3 4)))
(fringe x)
(1 2 3 4)

(fringe (list x x))
(1 2 3 4 1 2 3 4)

(define x (list (list 1 2) (list 3 4)))
x
(define (fringe x)
  (if (null? x) '()
    (if (and (pair? (car x)) (not (pair? (car (car x)))))
        (append (car x) (car (cdr x)))
        (append (fringe (car x)) (fringe (cdr x)))
    )
  )
)

(fringe x)
(fringe (list x x))

results matching ""

    No results matching ""