예제 #1
0
 public void postOrderTraversal(LambdaOne<IntBinaryTree> function) {
   // Post-order traversal of each child.
   if (leftChild != null) {
     leftChild.postOrderTraversal(function);
   }
   if (rightChild != null) {
     rightChild.postOrderTraversal(function);
   }
   // Visit this node.
   function.call(this);
 }
예제 #2
0
 /** 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());
 }
예제 #3
0
 /** Gets the leaves of this tree. */
 public ArrayList<IntBinaryTree> getLeaves() {
   LeafCollector leafCollector = new LeafCollector();
   postOrderTraversal(leafCollector);
   return leafCollector.leaves;
 }