예제 #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
 /**
  * @link http://php.net/manual/en/iterator.current.php
  * @return mixed
  */
 function current()
 {
     return $this->value->value();
 }
예제 #3
0
 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;
 }