Skip to content

Instantly share code, notes, and snippets.



Created Feb 26, 2013
What would you like to do?
(define (grow-huffman-tree pairs)
(define (make-tree leaf-set)
((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.