; Code for aLisp tree
; the below function creates a node with items in it.
(
defun
make
-
tree (item)
(cons (cons item
nil
)
nil
)
)
; Function below will take two tree
; nodes and add the second tree as the child of the
; first.
(
defun
add
-
child (tree child)
(
setf
(
car
tree) (
append
(
car
tree) child))
tree
)
; Function below will take a tree node and return
; the first child of that node or
nil
,
;
if
this node does
not
have any child node.
(
defun
first
-
child (tree)
(
if
(null tree)
nil
(
cdr
(
car
tree))
)
)
; it takes a tree node as argument, and returns
; a reference to the next sibling node,
; or
nil
,
if
the node does
not
have any
(
defun
next
-
sibling (tree)
(
cdr
tree)
)
;a function to return the information in a node
(
defun
data (tree)
(
car
(
car
tree))
)
(setq tree '((
1
3
(
2
6
9
) ( (
4
7
8
)))))
(setq mytree (make
-
tree
60
))
(write (data mytree))
(terpri)
(write (first
-
child tree))
(terpri)
(setq newtree (add
-
child tree mytree))
(terpri)
(write newtree)