Preoder traversal of a Btree
- by Phenom
I'm trying to figure out how to do a preorder traversal of a Btree. I know that generally preorder traversal works like this:
preorder(node)
{
print value in node
preorder(left child)
preorder(right child)
}
What's confusing to me is how to make this work with a Btree, since in each node there are multiple values and multiple child pointers. When printing values, do all the values in the node get printed before descending into the left child?
Each node looks like this:
child1 value1 child2 value2 child3 value3 child4
Also, why would anyone want to do a preorder traversal of a Btree, since an inorder traversal is what will display the values in ascending order?