Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Recursive to Iterative algorithms

Name: Anonymous 2006-10-10 4:17

hi. is it possible to write an iterative version of the post-order and in-order binary tree traversal algorithms? I know how to do the one for preorder using stacks, but I can't get my head around the other two.

please help
friend,

Name: Anonymous 2011-06-18 23:07

>>9
need a stack
You do?

(define (traverse f tree)
  (call/ec
   (let walk ((tree tree) (r '()))
     (lambda (k)
       (cond ((null? tree) (k r))
             ((pair? tree)
              ((walk (car tree) r)
               (lambda (v)
                 ((walk (cdr tree) r)
                  (lambda (v2)
                    (k (cons v v2)))))))
             (else (k (f tree))))))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List