Depth first traversal can be accomplished with an array and unshift, breadth-first search via an array and push. Following pseudo-code converts to a flat list:
# -*- pseudo-mode -*- traverse_queue = [ root ]; work_queue = []; while ( work_queue is_not empty ) { node = shift( traverse_queue ); push( work_queue, node ) if BFS; push/unshift( traverse_queue, children ); push( work_queue, node ) if DFS; }
--MidLifeXis
In reply to Re: Binary tree without recurssion
by MidLifeXis
in thread Binary tree without recurssion
by punitpawar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |