home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 2: PC
/
frozenfish_august_1995.bin
/
bbs
/
d09xx
/
d0963.lha
/
SIOD
/
scm
/
tree-imper.scm
< prev
next >
Wrap
Text File
|
1999-12-31
|
1KB
|
29 lines
(define (pre-ord tree)
(define pila (make-pila))
(define out '())
(do ()
((and (empty-tree? tree) (empty-pila? pila))
(reverse out))
(if (empty-tree? tree)
(begin (set! tree (top pila))
(pop! pila))
(begin (set! out (cons (entry tree) out))
(push! (right-branch tree) pila)
(set! tree (left-branch tree))))))
(define (in-ord tree)
(define pila (make-pila))
(define out '())
(do ()
((and (empty-tree? tree) (empty-pila? pila))
(reverse out))
(if (empty-tree? tree)
(let ((p (top pila)))
(set! out (cons (car p) out))
(set! tree (cdr p))
(pop! pila))
(begin (push! (cons (entry tree)
(right-branch tree))
pila)
(set! tree (left-branch tree))))))