乐正

Actions speak louder than words.

Sicp-ex2-67

问题

请定义一棵编码树和一个样例消息:

1
2
3
4
5
6
7
8
(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完成该消息的编码,请给出编码的结果。

解答

1
2
3
4
;; (load 'p112-huffman-tree.scm)

(decode sample-message sample-tree)
;Value 23: (a d a b b c a)

draft

« sicp-ex2-66 sicp-ex2-68 »

Comments