I'm trying to build a binary tree is lisp. The function should do this
(buildBST ‘(6 9 2 1 7)) -> (6 (2 (1) ()) (9 (7) ()))
The code we have so far will keep returning the error
> 7 nil arguments should be of type real
Here's our code
(defun buildBst (lis)
(cond
((null lis) 0)
((atom lis) lis)
(t (if ( >(car lis)(car(cdr lis)))
(buildBst( cdr lis))
(buildBst(cdr lis))))))
lisonly has 1 element. You do(> (car lis) (car (cdr lis)), but if there's only 1 element,(car (cdr lis))will beNIL.ifstatement do exactly the same thing? Is that really what you want there?