灯下 登录
计算机科学 / SICP / 2.3.4 Example: Huffman Encoding Trees

Exercise 2.67 · 习题

Exercise 2.67: Define an encoding tree and a
sample message:

(define sample-tree
(make-code-tree
(make-leaf 'A 4)
(make-code-tree
(make-leaf 'B 2)
(make-code-tree
(make-leaf 'D 1)
(make-leaf 'C 1)))))

(define sample-message
'(0 1 1 0 0 1 0 1 0 1 1 1 0))

Use the decode procedure to decode the message, and give the result.

练习 2.67:定义一棵编码树和一条样本消息:

(define sample-tree
(make-code-tree
(make-leaf 'A 4)
(make-code-tree
(make-leaf 'B 2)
(make-code-tree
(make-leaf 'D 1)
(make-leaf 'C 1)))))

(define sample-message
'(0 1 1 0 0 1 0 1 0 1 1 1 0))

使用 decode 过程对该消息解码,并给出结果。

Racket #lang sicp
(define sample-tree
 (make-code-tree
 (make-leaf 'A 4)
 (make-code-tree
 (make-leaf 'B 2)
 (make-code-tree
 (make-leaf 'D 1)
 (make-leaf 'C 1)))))

(define sample-message
 '(0 1 1 0 0 1 0 1 0 1 1 1 0))