EX 2.68

(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))
- Login to post comments
- 1322 reads
Comments
Thu, 2007/03/29 - 19:41 — porco

不对吧,好像无法生成00,01这样的编码
...... full content is only available to community members.
- Login to post comments
Sat, 2008/10/11 - 21:31 — panxingzhi

处理树的非叶节点时有问题
...... full content is only available to community members.
- Login to post comments
Thu, 2008/11/13 - 02:12 — admin

最初给定的 tree 也许是棵单叶树
...... full content is only available to community members.
- Login to post comments
|
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> |