previous | index | next

A More Efficient preorder

     (preorder bushy-tree)
     |(cons 7 ())
     |(7)
     |(cons 5 (7))
     |(5 7)
     |(cons 6 (5 7))
     |(6 5 7)
     |(cons 3 (6 5 7))
     |(3 6 5 7)
     |(cons 1 (3 6 5 7))
     |(1 3 6 5 7)
     |(cons 2 (1 3 6 5 7))
     |(2 1 3 6 5 7)
     |(cons 4 (2 1 3 6 5 7))
     |(4 2 1 3 6 5 7)
     (4 2 1 3 6 5 7)
7 calls to cons, the same as the number of nodes.

previous | index | next