EX 2.69

netawater's picture
(define (adjoin-set x set)
  (cond ((null? set) (list x))
        ((< (weight x) (weight (car set))) (cons x set))
        (else (cons (car set)
                    (adjoin-set x (cdr set))))))

(define (make-leaf-set pairs)
  (if (null? pairs)
      '()
      (let ((pair (car pairs)))
        (adjoin-set (make-leaf (car pair) ; symbol
                               (cadr pair)) ; frequency
                    (make-leaf-set (cdr pairs))))))

(define (make-leaf symbol weight)
  (list 'leaf symbol weight))

(define (leaf? object)
  (eq? (car object) 'leaf))

(define (symbol-leaf x) (cadr x))

...... full content is only available to community members.

Comments

zbelial's picture

上面的程序有错误?

...... full content is only available to community members.

panxingzhi's picture

不用那么麻烦吧

...... full content is only available to community members.

code17's picture

两点建议

...... full content is only available to community members.

code17's picture

用 descending sorted set 那部分的算法是错的

...... full content is only available to community members.