以下代码在计算有多少值小于或等于用户输入的值“z”方面是否有任何错误?特别希望有人看一下这段代码的最终功能,告诉我是否有任何错误。
(define (create-heap v H1 H2)
(list v H1 H2))
(define (h-min H) (car H))
(define (left H) (cadr H))
(define (right H) (caddr H))
(define (insert-h x H)
(if (null? H)
(create-heap x '() '())
(let ((child-value (max x (h-min H)))
(root-value (min x (h-min H))))
(create-heap root-value
(right H)
(insert-h child-value (left H))))))
(define (insert-all lst H)
(if (null? lst)
H
(insert-all (cdr lst) (insert-h (car lst) H))))
(define (count-less-than-or-equal-in-heap z H)
(cond ((or (null? H) (> (h-min H) z)) 0)
(else
(+ 1 (count-less-than-or-equal-in-heap z (right H))
(count-less-than-or-equal-in-heap z (left H))))
))