0

我正在尝试将一个项目插入到二叉搜索树中,但我遇到了一个错误,我不明白为什么。如果我尝试运行:

(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)))))

该错误特别指出 (> e (node tree)) 是有问题的代码段。有谁知道这里发生了什么?

4

1 回答 1

2

You double quoted, try

(insert 11 '(5 () ()))
于 2013-11-09T16:55:44.153 回答