I am trying to do a lisp function that will receive a list and will return a complete binary tree whose nodes are populated from the elements of the list in the same order.
For example,
(makeTree '(4 3 9 10))
(4 (3 (9 () ()) ()) (10 () ()))
To do it, I am using a function that splits the list in 2. So, what I did is tried to separate the head of the list from it's tail and then use the split function to be able to do the binary tree. But I am having trouble implementing it. Can someone help me please?
Here is my code so far:
(defun aux-head (l n)
(if (= n 0) '()
(cons (car l) (aux-head (cdr l)(- n 1)))))
(defun aux-tail (l n)
(if (= n 0) l
(aux-tail (cdr l) (- n 1))))
(defun split (lst)
(cond
((null lst) '(()()))
((evenp (length lst))
(list (aux-head lst (/ (length lst) 2))(aux-tail lst (/ (length lst) 2))))
((oddp (length lst))
(list (aux-head lst (+ (floor (length lst) 2) 1))
(aux-tail lst (+ (floor (length lst) 2) 1))))))
(defun make-cbtree (lst)
(cond
((null lst) '(()()))
((car lst)
((split ((cdr lst)))))))

(4 (3 (9 () ()) ()) (10 () ())), not(4 (3 (9 () ()) (10 () ())) ())? is there any special ruleset? because otherwise the task is ambiguous