(define (inOrderTraverse root)
(cond
[(not (list? root)) (display root)]
[else (
(inOrderTraverse (getLeftChild root))
(display (getValue root))
(inOrderTraverse (getRightChild root))
)]
)
)
I tried replacing cond
with if
, but that didn't work.
I looked up online for similar approaches and found:
(define (inorder ~node func)
(unless (empty? ~node)
(inorder (node-left ~node) func)
(print (node-val ~node)) (print ", ")
(inorder (node-right ~node) func)))
from a gist of github/arjunvasan. After editing their code to fit mine, it worked perfectly, with the only difference being that they used unless
instead of cond
.
Why does unless
work better here? I checked the racket docs on this keyword but still haven't found it.