コード例 #1
0
ファイル: Formula.cs プロジェクト: predragf/propas
 private int calculateDepth(Node rootNode, int depth)
 {
     if (rootNode == null || rootNode is LeafNode)
     {
         depth = depth > 0 ? depth - 1 : depth;
     }
     else if (rootNode is InternalNode)
     {
         InternalNode opNode = (InternalNode)rootNode;
         depth = calculateDepth(opNode.getLeftHandSide(), depth + 1);
         int rhsDepth = calculateDepth(opNode.getRightHandSide(), depth + 1);
         if (rhsDepth > depth)
         {
             depth = rhsDepth;
         }
     }
     return(depth);
 }
コード例 #2
0
ファイル: Formula.cs プロジェクト: predragf/propas
        private ICollection <Node> getLeafsRecursively(Node node)
        {
            List <Node> result = new List <Node>();

            if (node is LeafNode)
            {
                if (!string.IsNullOrWhiteSpace(node.getExpression()))
                {
                    result.Add(node);
                }
            }
            else if (node is InternalNode)
            {
                InternalNode operatorNode = (InternalNode)node;
                result.AddRange(getLeafsRecursively(operatorNode.getLeftHandSide()));
                result.AddRange(getLeafsRecursively(operatorNode.getRightHandSide()));
            }
            return(result);
        }
コード例 #3
0
ファイル: Formula.cs プロジェクト: predragf/propas
        private ICollection <Node> recursiveTraversal(int currentLevel, int requestedLevel, Node currentNode)
        {
            List <Node> result = new List <Node>();

            if (currentNode is InternalNode)
            {
                InternalNode currentOperator = (InternalNode)currentNode;
                if (currentLevel <= requestedLevel)
                {
                    result.AddRange(recursiveTraversal(currentLevel + 1, requestedLevel, currentOperator.getLeftHandSide()));
                    result.AddRange(recursiveTraversal(currentLevel + 1, requestedLevel, currentOperator.getRightHandSide()));
                }
            }
            else if (currentNode is LeafNode)
            {
                if (currentLevel == 0 || currentLevel == requestedLevel + 1)
                {
                    result.Add(currentNode);
                }
            }


            return(result);
        }