Skip to content

Instantly share code, notes, and snippets.

@htor

htor/huff.scm

Created Feb 26, 2013
Embed
What would you like to do?
Riktig-ish?
(define (grow-huffman-tree pairs)
(define (make-tree leaf-set)
(cond
((null? leaf-set) '()) ; no element
((null? (cdr leaf-set)) (car leaf-set)) ; one element
(else ; two elements
(let ((first (car leaf-set))
(second (cadr leaf-set))
(rest (cddr leaf-set)))
(if (null? rest)
(make-code-tree first second)
(make-code-tree (make-code-tree first second)
(make-tree rest)))))))
(make-tree (make-leaf-set pairs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.