练习2.24 2.26

来源:互联网 发布:正规淘宝代运营公司 编辑:程序博客网 时间:2024/04/27 22:02
#|(define x (cons (list 1 2) (list 3 4)))(length x)(define (count-leaves tree)  (cond ((null? tree) 0)        ((not (pair? tree)) 1) ;: 叶子        (else (+ (count-leaves (car tree))                 (count-leaves (cdr tree))))))(count-leaves x)|#;: 练习 2.24(list 1 (list 2 (list 3 4))) ;: '(1 (2 ( 3 4)))#|;: 盒子(list a b) => (cons a (cons b nil));: 图为[.][.]-->[.][.]-->nil |        | |        | V        V a        b(list 1 (list 2 (list 3 4))) ;:  [.][.]--------------->[.][.]-->nil|                      ||                      |V                      V        1  (list 2 (list 3 4))[.][.]--->[.][.]-->nil                        |         |                       |         |                       V         |                       2         V                      (list 3 4)[.][.]-->[.][.]-->nil                                 |        |                                            |        |                                               V        V                                                  3        4                 ;: 树(1 (2 (3 4)))    .   / \  1   . (2 (3 4))     / \    2   .( 3 4)       / \      3  4|#;:  练习 2.25(car ;:7 (cdr ;: '(7)  (car ;: '(5 7)   (cdr ;: '((5 7) 9)     (cdr '(1 2 (5 7) 9)) ;: '(2 (5 7) 9)    ))))(car (car '((7))))(car ;: 7 (cdr ;: '(7)  (cdr   (cdr    (cdr     (cdr      (cdr '(1 2 3 4 5 6 7) ;:'(2 3 4 5 6 7)           )))))))#|;: 练习 2.6(define x (list 1 2 3))(define y (list 4 5 6))(cons x y) ;: '((1 2 3) 4 5 6)(list x y) ;: '((1 2 3) (4 5 6))|#
0 0
原创粉丝点击