|
|
|
|
|
by mubou
419 days ago
|
|
I bet you could do something generic like this in languages that have deferred execution like C#'s IEnumerable. Something like foreach (Node node in EnumerateNodes(root, x => x != null, x => [x.Left, x.Right]))
where EnumerateNodes uses `yield return` (i.e. is a generator) and calls itself recursively. Though it'd probably be easier / better performance to write an implementation specific to each node type. |
|