int sumDepthOfAllChildren(Node node, int depth) { if ( node == null ) return 0; // starting to see a pattern? return depth + sumDepthOfAllChildren(node.getLeft(), depth + 1) + sumDepthOfAllChildren(node.getRight(), depth + 1); }
int countChildren(Node node) { if ( node == null ) return 0; return 1 + countChildren(node.getLeft()) + countChildren(node.getRight()); }
/** * INTERNAL * Does this node have a left */ public boolean hasLeft() { return getLeft() != null; }
/** * INTERNAL * Does this node have a left */ public boolean hasLeft() { return getLeft() != null; }
/** * INTERNAL * Does this node have a left */ public boolean hasLeft() { return getLeft() != null; }
public int depth(Node root){ if(root == null) { return 0; } else return 1 + Math.max((root.getLeft(), root.getRight()); }
public static TreeAttr calcTreeDiameter(Node root) { if (root == null) return new TreeAttr(0, 0); TreeAttr leftAttr = calcTreeDiameter(root.getLeft()); TreeAttr rightAttr = calcTreeDiameter(root.getRight()); int maxDepth = Math.max(leftAttr.depth, rightAttr.depth); int maxDiam = Math.max(leftAttr.diameter, rightAttr.diameter); maxDiam = Math.max(maxDiam, leftAttr.depth + rightAttr.depth + 1); return new TreeAttr(maxDiam, maxDepth + 1); }
T search(Node tree, T val) { int delta = tree.getValue.compareTo(val); if (delta == 0) { return tree.getValue; } else if (delta > 0) { return search(tree.getRight(), val); } else { return search(tree.getLeft(), val); } }
T search(Node tree, T val) { if (tree == null) return null; int delta = tree.getValue.compareTo(val); if (delta == 0) { return tree.getValue; } else if (delta > 0) { return search(tree.getRight(), val); } else { return search(tree.getLeft(), val); } }
public int countNodes(Node root) { // Setup // assign to temps to avoid double call accessors. Node left = root.getLeft(); Node right = root.getRight(); int count = 1; // count THIS node. // count subtrees if (left != null) count += countNodes(left); if (right != null) count += countNodes(right); return count; }
public int sumT(Node nodo) { if (nodo == null) return 0; return sumT(nodo.getLeft()) + sum(nodo.getRight()) + nodo.getValor(); }
public static void preorder(Node root) { if(root == null) return; root.printValue(); preorder(root.getLeft()); preorder(root.getRight()); return; }
void inorderTraversal( Node root ){ if( root == null ) return; inorderTraversal( root.getLeft() ); root.printValue(); inorderTraversal( root.getRight() ); }
private boolean selectingRelationshipField(Node node, GenerationContext context) { if ((node == null) || !node.isDotNode()) { return false; } TypeHelper typeHelper = context.getParseTreeContext().getTypeHelper(); Node path = node.getLeft(); AttributeNode attribute = (AttributeNode)node.getRight(); return typeHelper.isRelationship(path.getType(), attribute.getAttributeName()); }
private boolean selectingRelationshipField(Node node, GenerationContext context) { if ((node == null) || !node.isDotNode()) { return false; } TypeHelper typeHelper = context.getParseTreeContext().getTypeHelper(); Node path = node.getLeft(); AttributeNode attribute = (AttributeNode)node.getRight(); return typeHelper.isRelationship(path.getType(), attribute.getAttributeName()); }
private boolean selectingRelationshipField(Node node, GenerationContext context) { if ((node == null) || !node.isDotNode()) { return false; } TypeHelper typeHelper = context.getParseTreeContext().getTypeHelper(); Node path = node.getLeft(); AttributeNode attribute = (AttributeNode)node.getRight(); return typeHelper.isRelationship(path.getType(), attribute.getAttributeName()); }
/** * INTERNAL * Apply this node to the passed query */ public void applyToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) { if (theQuery.isReportQuery()) { ReportQuery reportQuery = (ReportQuery)theQuery; reportQuery.addAttribute("size", getLeft().generateExpression(context).count(), (Class)getType()); reportQuery.addGrouping(getLeft().getLeft().generateExpression(context)); } }
/** * INTERNAL * Apply this node to the passed query */ public void applyToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) { if (theQuery.isReportQuery()) { ReportQuery reportQuery = (ReportQuery)theQuery; reportQuery.addAttribute("size", getLeft().generateExpression(context).count(), (Class)getType()); reportQuery.addGrouping(getLeft().getLeft().generateExpression(context)); } }
/** * INTERNAL * Apply this node to the passed query */ public void applyToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) { if (theQuery.isReportQuery()) { ReportQuery reportQuery = (ReportQuery)theQuery; reportQuery.addAttribute("size", getLeft().generateExpression(context).count(), (Class)getType()); reportQuery.addGrouping(getLeft().getLeft().generateExpression(context)); } }