(define x (list (list 1 2) (list 3 4)))
x
(car (cdr x))
(car x)
(define (deep-reverse items)
(display items)
(newline)
(cond
((null? items) ())
(( not (pair? items)) items)
( (pair? items)
(list (deep-reverse (car (cdr items)))
(deep-reverse (car items))
)
)
)
)
(deep-reverse x)
(define x (list (list 1 2) (list 3 4)))
(define (fringe items)
(cond
((null? items) ())
((not (pair? items)) (list items) )
(else
(append (fringe (car items)) (fringe (car (cdr items))))
)
)
)
(fringe x)
(define (left-branch items)
(car (car (cdr items)))
)
(define (right-branch items)
(car (cdr (car (cdr items))))
)
(define (branch-length items)
(car items)
)
(define (branch-structure items)
(car (cdr items))
)
(branch-length x)
(branch-structure x)
(left-branch x)
(right-branch x)
(define (total-weight items)
(cond
((not (pair? items)) 0)
(else (+ (branch-length items) (+ (branch-length (left-branch items)) (branch-length(right-branch items))) ))
)
)
(total-weight z)
SICP Exercise 2.20+
最新推荐文章于 2024-09-21 11:38:30 发布
本文通过具体的Scheme语言示例展示了如何使用递归和条件判断来处理列表数据结构,包括反转列表、提取元素、计算总权重等操作。
317

被折叠的 条评论
为什么被折叠?



