| @@ 363-372 (lines=10) @@ | ||
| 360 | * @param Callable|null $callback the callback function to apply to each |
|
| 361 | * node. |
|
| 362 | */ |
|
| 363 | private function _preorder($node, Callable $callback = null) { |
|
| 364 | if($node === null) { |
|
| 365 | return; |
|
| 366 | } |
|
| 367 | if($callback !== null) { |
|
| 368 | call_user_func($callback, $node); |
|
| 369 | } |
|
| 370 | $this->_preorder($node->left, $callback); |
|
| 371 | $this->_preorder($node->right, $callback); |
|
| 372 | } |
|
| 373 | ||
| 374 | /** |
|
| 375 | * Traverse in inorder. This is: first visit the left subtree, |
|
| @@ 393-403 (lines=11) @@ | ||
| 390 | * @param Callable|null $callback the callback function to apply to each |
|
| 391 | * node. |
|
| 392 | */ |
|
| 393 | private function _inorder($node, Callable $callback = null) { |
|
| 394 | if($node === null) { |
|
| 395 | return; |
|
| 396 | } |
|
| 397 | ||
| 398 | $this->_inorder($node->left, $callback); |
|
| 399 | if($callback !== null) { |
|
| 400 | call_user_func($callback, $node); |
|
| 401 | } |
|
| 402 | $this->_inorder($node->right, $callback); |
|
| 403 | } |
|
| 404 | ||
| 405 | /** |
|
| 406 | * Traverse in postorder. This is: first visit the left subtree, |
|
| @@ 424-433 (lines=10) @@ | ||
| 421 | * @param Callable|null $callback the callback function to apply to each |
|
| 422 | * node. |
|
| 423 | */ |
|
| 424 | private function _postorder($node, Callable $callback = null) { |
|
| 425 | if($node === null) { |
|
| 426 | return; |
|
| 427 | } |
|
| 428 | $this->_postorder($node->left, $callback); |
|
| 429 | $this->_postorder($node->right, $callback); |
|
| 430 | if($callback !== null) { |
|
| 431 | call_user_func($callback, $node); |
|
| 432 | } |
|
| 433 | } |
|
| 434 | ||
| 435 | /** |
|
| 436 | * Binds to count() method. This is equal to make $this->tree->size(). |
|