@@ 155-164 (lines=10) @@ | ||
152 | * @param Callable|null $callback the callback function to apply to each |
|
153 | * node. |
|
154 | */ |
|
155 | private function _preorder($node, Callable $callback = null) { |
|
156 | if($node === null) { |
|
157 | return; |
|
158 | } |
|
159 | if($callback !== null) { |
|
160 | call_user_func($callback, $node); |
|
161 | } |
|
162 | $this->_preorder($node->left, $callback); |
|
163 | $this->_preorder($node->right, $callback); |
|
164 | } |
|
165 | ||
166 | /** |
|
167 | * Traverse in inorder. This is: first visit the left subtree, |
|
@@ 185-195 (lines=11) @@ | ||
182 | * @param Callable|null $callback the callback function to apply to each |
|
183 | * node. |
|
184 | */ |
|
185 | private function _inorder($node, Callable $callback = null) { |
|
186 | if($node === null) { |
|
187 | return; |
|
188 | } |
|
189 | ||
190 | $this->_inorder($node->left, $callback); |
|
191 | if($callback !== null) { |
|
192 | call_user_func($callback, $node); |
|
193 | } |
|
194 | $this->_inorder($node->right, $callback); |
|
195 | } |
|
196 | ||
197 | /** |
|
198 | * Traverse in postorder. This is: first visit the left subtree, |
|
@@ 216-225 (lines=10) @@ | ||
213 | * @param Callable|null $callback the callback function to apply to each |
|
214 | * node. |
|
215 | */ |
|
216 | private function _postorder($node, Callable $callback = null) { |
|
217 | if($node === null) { |
|
218 | return; |
|
219 | } |
|
220 | $this->_postorder($node->left, $callback); |
|
221 | $this->_postorder($node->right, $callback); |
|
222 | if($callback !== null) { |
|
223 | call_user_func($callback, $node); |
|
224 | } |
|
225 | } |
|
226 | } |