Search code examples
ctree2-3-tree

How do I parse a whole 2-3 tree?


I have a 2-3 tree with the following node structure:

struct node
{
    int value1, value2;
    node *parent, *left, *right, *middle;
}

The problem is I don't know how to parse the whole tree. I know how we search for it because you simply go to the right path. But how to I get to check all the nodes in the tree?


Solution

  • Here is pseudocode, that might help:

       void ParseNode(node *n)
       {
            OperationToParseCurrentNode();
    
            if(n->left)
               ParseNode(n->left);
            if(n->middle)
               ParseNode(n->middle);
            if(n->right)
               ParseNode(n->right);
       }
    

    This will traverse all nodes if you input the root node.