Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # iterative
- function traverse($tree) {
- $stack = [System.Collections.Stack]::new()
- $stack.Push($tree)
- while ($stack.Count) {
- $node = $stack.Pop()
- if ($node.Left) {
- $stack.Push($node.Left)
- }
- if ($node.Right) {
- $stack.Push($node.Right)
- }
- ... # do something with the node
- }
- }
- # recursive
- function traverse($tree)
- $tree.left, $tree.right | ? {$_} | % {traverse $_}
- ... # do something with the node
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement