@Override public void call(IntBinaryTree node) { if (!node.isLeaf()) { node.start = node.leftChild.start; if (node.rightChild == null) { node.end = node.leftChild.end; } else { node.end = node.rightChild.end; } } }
/** Updates all the start end fields, treating the current node as the root. */ public void updateStartEnd() { ArrayList<IntBinaryTree> leaves = getLeaves(); for (int i = 0; i < leaves.size(); i++) { IntBinaryTree leaf = leaves.get(i); leaf.start = i; leaf.end = i + 1; } postOrderTraversal(new UpdateStartEnd()); }