;;;-*- Mode: LISP; Syntax: Common-Lisp; Base: 10; Package: COMMON-LISP-USER -*- ;;; $Id: treeprint.lisp,v 1.1 1994/11/09 20:05:48 lyman Exp lyman $ ;;; $Revision: 1.1 $ ;;;; Overview ;;; Author: Lyman Taylor ( lyman@cc.gatech.edu ) ;;; Company: Buckaroo Banzai Institute ;;; ;;; ;;; ;;; If you have the selectors (left-child , right-child ) and ;;; predicate (empty-tree-p )used by this function you ;;; can print you trees "sideways". Namely the root will ;;; appears leftmost and the "leaves" appear rightmost. ;;; Rotating your head 90 degress counterclockwise will show the tree ;;; structure. ;;; (defun tree-print ( tree &optional ( depth 0 ) ) "This is print out the nodes of a tree by doing an 'reverse order' traversal. It is actually in reverse order so the when result is rotated 90 degrees clockwise the left-child will appear on the left." (let ((format-string (if (= depth 0 ) (format nil "~% ~~A") (format nil "~% ~~~A,8T ~~A" (* depth 8 ) )))) (cond ((empty-tree-p tree ) nil ) ( t (tree-print (right-child tree ) (1+ depth)) (format *query-io* format-string (tree-key tree )) (tree-print (left-child tree) (1+ depth)))))) ;;; EOF ;;;;;;;