Encode Huffman Tree Scheme

╄→гoц情女王★ 提交于 2020-04-21 05:27:19

问题


I am trying to build a function that encodes the following procedure at the bottom into 1's and 0's can anyone help find why I am getting the error message mpair given: 0.

(define (symbols tree)
  (if (leaf? tree)
      (list (symbol-leaf tree))
      (caddr tree)))
(define (right-branch tree) (cadr tree))
(define (left-branch tree) (car tree))
(define (leaf? object)
  (eq? (car object) 'leaf))
(define (member? x set)
  (not (equal? (member x set) false)))
(define (encode-branch symbol tree)
  (let ((left (left-branch tree))
        (right (right-branch tree)))
    (cond ((member? symbol (symbols left)) (list 0 left))
          ((member? symbol (symbols right)) (list 1 right))
          (else (error symbol tree)))))
(define (encode symbol tree)
  (if (leaf? tree) '()
      (let ((new-branch (encode-branch symbol tree)))
        (cons (car new-branch) (encode symbol (cadr new-branch))))))

(encode "doo doo doo da da da da" '((da . 00) (doo . 01) (ron . 1)))

来源:https://stackoverflow.com/questions/47149369/encode-huffman-tree-scheme

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!