EX 2.68

netawater's picture
(define (make-leaf symbol weight)
  (list 'leaf symbol weight))

(define (leaf? object)
  (eq? (car object) 'leaf))

(define (symbol-leaf x) (cadr x))

(define (weight-leaf x) (caddr x))

(define (make-code-tree left right)
  (list left
        right
        (append (symbols left) (symbols right))
        (+ (weight left) (weight right))))

(define (symbols tree)
  (if (leaf? tree)
      (list (symbol-leaf tree))
      (caddr tree)))

(define (weight tree)
  (if (leaf? tree)
      (weight-leaf tree)
      (cadddr tree)))

(define (left-branch tree) (car tree))

...... full content is only available to community members.

Comments

porco's picture

不对吧,好像无法生成00,01这样的编码

...... full content is only available to community members.

panxingzhi's picture

处理树的非叶节点时有问题

...... full content is only available to community members.

admin's picture

最初给定的 tree 也许是棵单叶树

...... full content is only available to community members.