tree - Non recursive Depth first search algorithm -


i looking non recursive depth first search algorithm non binary tree. appreciated.

dfs:

list nodes_to_visit = {root}; while( nodes_to_visit isn't empty ) {   currentnode = nodes_to_visit.take_first();   nodes_to_visit.prepend( currentnode.children );   //do } 

bfs:

list nodes_to_visit = {root}; while( nodes_to_visit isn't empty ) {   currentnode = nodes_to_visit.take_first();   nodes_to_visit.append( currentnode.children );   //do } 

the symmetry of 2 quite cool.

update: pointed out, take_first() removes , returns first element in list.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -