| Conditions | 4 |
| Paths | 5 |
| Total Lines | 15 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function travel(Node $node, $visitor) |
||
| 22 | { |
||
| 23 | $queue = new \SplQueue(); |
||
| 24 | $queue->enqueue($node); |
||
| 25 | |||
| 26 | while (!$queue->isEmpty()) { |
||
| 27 | $node = $queue->dequeue(); |
||
| 28 | $visitor($node); |
||
| 29 | |||
| 30 | //压左子树 |
||
| 31 | if ($node->getLeft()) { |
||
| 32 | $queue->push($node->getLeft()); |
||
| 33 | } |
||
| 34 | if ($node->getRight()) { |
||
| 35 | $queue->push($node->getRight()); |
||
| 36 | } |
||
| 39 | } |