Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best UML diagram for explaining recursive tree traversal?

I want to explain my C# code which traverses a parse tree for code analysis. It is similar to the following but longer:

    private void traverse(ParseTreeNode node)
    {
        if (node.ChildNodes.Count == 0)
        {
            return;
        }

        switch (node.Term.Name.ToUpper())
        {
            case "FILE":
                traverse(node.ChildNodes[0]);
                return;

            case "PROGRAM":
                traverse(node.ChildNodes[0]);
                return;

            //etc.
        }
    }

What is the most appropriate UML diagram for showing this? Thanks

like image 456
Rob Crocombe Avatar asked Nov 02 '22 00:11

Rob Crocombe


1 Answers

Continuing the discussion arisen in the comments after dasblinkenlight's answer, I suggest the following activity diagram as a solution:

enter image description here

Activity diagram puts an emphasis on the sequence of steps in a process/algorithm, decisions made on the way, manipulated data and calculations, eventually concurrent tasks, invocations, etc.

There is always some kind of context to activity diagram. In this case it is a method traverse().

like image 182
Aleks Avatar answered Nov 15 '22 04:11

Aleks