Conditions | 4 |
Paths | 5 |
Total Lines | 16 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
21 | public function travel(Node $node, $visitor) |
||
22 | { |
||
23 | $stack = new \SplStack(); |
||
24 | $stack->push($node); |
||
25 | |||
26 | while (!$stack->isEmpty()) { |
||
27 | $stack->top(); |
||
28 | $node = $stack->pop(); |
||
29 | $visitor($node); |
||
30 | |||
31 | //压右子树 |
||
32 | if ($node->getRight()) { |
||
33 | $stack->push($node->getRight()); |
||
34 | } |
||
35 | if ($node->getLeft()) { |
||
36 | $stack->push($node->getLeft()); |
||
37 | } |
||
40 | } |