예제 #1
0
    // After this call, all orbits should have a depth.
    public int GetOrbitsCount()
    {
        int counter             = 0;
        List <ObjectNode> queue = new List <ObjectNode>();

        queue.Add(treeRoot);  // initial node

        while (queue.Count != 0)
        {
            // Add Child nodes to the queue
            ObjectNode tmp = queue[0];
            queue.RemoveAt(0);
            foreach (ObjectNode node in tmp.GetChildren())
            {
                queue.Add(node);
            }

            // Get depth from parent ~ pseudo recursively.
            if (tmp.Depth == -1)
            {
                tmp.Depth = tmp.GetParent().Depth + 1;
            }
            counter += tmp.Depth;
        }

        return(counter);
    }