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

javascript - JS causing window size to be bigger than necessary - Dropdown bug -

php - Calling a template part from a post -

How to mention the localhost in android -