예제 #1
0
 protected function assertBinaryTree(BinaryTree $root)
 {
     $x = $root->value();
     $left = $root->left();
     if ($left !== null) {
         $y = $root->left()->value();
         $this->assertLessThan($x, $y);
         $this->assertBinaryTree($root->left());
     }
     $right = $root->right();
     if ($right !== null) {
         $y = $right->value();
         $this->assertLessThan($y, $x);
         $this->assertBinaryTree($root->right());
     }
 }
예제 #2
0
 private function next_valueNotNull()
 {
     $right = $this->value->right();
     if ($right !== null) {
         $this->stack->push($right);
     }
     $this->next_push($this->value->left());
 }
예제 #3
0
 /**
  * @param BinaryTree $node
  * @return int
  */
 private function deleteSelectState(BinaryTree $node)
 {
     $state = 0;
     $state |= ($node->right() != null) << 0;
     $state |= ($node->left() != null) << 1;
     return $state;
 }
예제 #4
0
 private function reCalculateHeights(BinaryTree $root = null)
 {
     if ($root === null) {
         return;
     }
     $this->reCalculateHeights($root->left());
     $this->reCalculateHeights($root->right());
     $root->recalculateHeight();
 }