插入二进制搜索树时出现合同违规错误

时间:2013-11-09 16:38:58

标签: scheme racket

我正在尝试将项目插入二叉搜索树,但我收到错误,我无法理解原因。 如果我试着跑:

(insert 11 '(5 '() '()))

错误是:

. . >: contract violation
  expected: real?
  given: quote
  argument position: 2nd
  other arguments...:
   11

主要代码:

(define (node tree)
    (car tree))

(define (right-branch tree)
    (caddr tree))

(define (left-branch tree)
    (cadr tree))

(define (make-tree node left-branch right-branch)
    (list node left-branch right-branch))

(define (insert e tree)
    (cond((null? tree) (make-tree e '() '()))           
        ((> e (node tree))(make-tree (node tree) (left-branch tree) (insert e (right-branch tree)))) 
        ((< e (node tree))(make-tree (node tree) (insert e (left-branch tree)) (right-branch tree)))))

该错误特别指出(&gt; e(节点树))作为有问题的代码段。 有谁知道这里发生了什么?

1 个答案:

答案 0 :(得分:2)

你双引号,试试

(insert 11 '(5 () ()))