Nuv Posted April 27, 2011 Share Posted April 27, 2011 I am trying to display binary tree level wise. Breadth-first tree traversal can be used in it.Can anyone point me towards its logic or point me towards a good tutorial. Quote Link to comment https://forums.phpfreaks.com/topic/234881-binary-tree-traversals/ Share on other sites More sharing options...
requinix Posted April 27, 2011 Share Posted April 27, 2011 Breadth-first means looking at children before looking at grandchildren. One simple way to do it is with a queue. queue = array(root node) while the queue is not empty { // not a foreach! node = the first item in the queue display the node for each child node { add the child node to the end of the queue } } Quote Link to comment https://forums.phpfreaks.com/topic/234881-binary-tree-traversals/#findComment-1207066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.