Jump to content

Binary tree traversals


Nuv

Recommended Posts

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
    }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.