| @@ 450-459 (lines=10) @@ | ||
| 447 | * @param Callable|null $callback the callback function to apply to each |
|
| 448 | * node. |
|
| 449 | */ |
|
| 450 | private function _preorder($node, Callable $callback = null) { |
|
| 451 | if($node === null) { |
|
| 452 | return; |
|
| 453 | } |
|
| 454 | if($callback !== null) { |
|
| 455 | call_user_func($callback, $node); |
|
| 456 | } |
|
| 457 | $this->_preorder($node->left, $callback); |
|
| 458 | $this->_preorder($node->right, $callback); |
|
| 459 | } |
|
| 460 | ||
| 461 | /** |
|
| 462 | * Traverse in inorder. This is: first visit the left subtree, |
|
| @@ 480-490 (lines=11) @@ | ||
| 477 | * @param Callable|null $callback the callback function to apply to each |
|
| 478 | * node. |
|
| 479 | */ |
|
| 480 | private function _inorder($node, Callable $callback = null) { |
|
| 481 | if($node === null) { |
|
| 482 | return; |
|
| 483 | } |
|
| 484 | ||
| 485 | $this->_inorder($node->left, $callback); |
|
| 486 | if($callback !== null) { |
|
| 487 | call_user_func($callback, $node); |
|
| 488 | } |
|
| 489 | $this->_inorder($node->right, $callback); |
|
| 490 | } |
|
| 491 | ||
| 492 | /** |
|
| 493 | * Traverse in postorder. This is: first visit the left subtree, |
|
| @@ 511-520 (lines=10) @@ | ||
| 508 | * @param Callable|null $callback the callback function to apply to each |
|
| 509 | * node. |
|
| 510 | */ |
|
| 511 | private function _postorder($node, Callable $callback = null) { |
|
| 512 | if($node === null) { |
|
| 513 | return; |
|
| 514 | } |
|
| 515 | $this->_postorder($node->left, $callback); |
|
| 516 | $this->_postorder($node->right, $callback); |
|
| 517 | if($callback !== null) { |
|
| 518 | call_user_func($callback, $node); |
|
| 519 | } |
|
| 520 | } |
|
| 521 | ||
| 522 | /** |
|
| 523 | * Binds to count() method. This is equal to make $this->tree->size(). |
|