- Code: Select all
`(defstruct (btnode)`

(val nil)

(left nil)

(right nil))

;; naive traversal functions

(defun traverse-pre-order (node fun)

(if node

(progn

(apply fun (list node))

(if (btnode-left node)

(traverse-pre-order (btnode-left node) fun))

(if (btnode-right node)

(traverse-pre-order (btnode-right node) fun)))))

(defun traverse-in-order (node fun)

(if node

(progn

(if (btnode-left node)

(traverse-in-order (btnode-left node) fun))

(apply fun (list node))

(if (btnode-right node)

(traverse-in-order (btnode-right node) fun)))))

(defun traverse-post-order (node fun)

(if node

(progn

(if (btnode-left node)

(traverse-post-order (btnode-left node) fun))

(if (btnode-right node)

(traverse-post-order (btnode-right node) fun))

(apply fun (list node)))))

[edited to put the code in a "[code]" block -- nuntius]