私は Dr. Racket を使用しており、言語は Pretty Big で、単純な二分探索木を "in?" で作成しようとしています。値が二分探索木にあるかどうかを返すメソッド。あらゆる種類の検索ツリー (文字列、int などを含むかどうか) を受け入れて、一般的である必要がありますが、このエラー メッセージが表示されて気が狂いそうです。コードは次のとおりです。
編集:: 現在は動作しますが、数字以外では動作しません (または、少なくとも文字列では動作しません)。新しい問題:
(define (bstsearch tree value)
(cond
((null? tree) #f)
((< value (car tree))
(bstsearch (cadr tree) value))
((> value (car tree))
(bstsearch (caddr tree) value))
((= value (car tree))
#t)
))
私が受け取っているエラーは言う:
<: expects type <real number> as 1st argument, given: "horse"; other arguments were: "horse"
使用時:
(bstsearch '("horse" ("cow" () ("dog" () ())) ("zebra" ("yak" ()()) ())) "horse")
入力として。