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()); } }
/** * @link http://php.net/manual/en/iterator.current.php * @return mixed */ function current() { return $this->value->value(); }
private function findNode($element, BinaryTree $context = null) { while ($context !== null) { $comparisonResult = call_user_func($this->comparator, $element, $context->value()); if ($comparisonResult < 0) { $context = $context->left(); } elseif ($comparisonResult > 0) { $context = $context->right(); } else { return $context; } } return null; }