EX 2.69

Tue, 2006/09/19 - 09:20 — netawater
(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))))))
(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))
- Login to post comments
- 2254 reads
Comments
Wed, 2008/04/30 - 19:33 — zbelial

上面的程序有错误?
...... full content is only available to community members.
- Login to post comments
Sat, 2008/10/11 - 21:30 — panxingzhi

不用那么麻烦吧
...... full content is only available to community members.
- Login to post comments
Fri, 2008/11/14 - 22:19 — code17

用 descending sorted set 那部分的算法是错的
...... full content is only available to community members.
- Login to post comments
|
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> |