我正在尝试编写一个 Huffman-leaves 程序;该过程从创建的霍夫曼树中返回一个对列表。运行方式示例
(huffman-leaves sample-tree)
->((A . 8) (C . 5) (B . 1) (D . 1))
我想出了什么,但让作家们阻止了......
(define (huffman-leaves tree)
(define (huffman-get-pairs current-branch pairs)
(if (or (null? tree) (null? current-branch))
pairs
(let ((next-branch
(get-branch (car current-branch) current-branch)))
(not (member? next-branch pairs)
(if (leaf? next-branch)
(cons (append pairs next-branch)
(display pairs)
(huffman-get-pairs (cadr current-branch) pairs))
(huffman-get-pairs next-branch pairs))))))
(huffman-get-pairs tree '()))
(member? item 'list) #if item in list return #t else #false
我知道我做错了什么,但我看不到。如何停止在方案中的霍夫曼树中搜索?我应该做不同的任何提示?