Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. # iterative
  2. function traverse($tree) {
  3. $stack = [System.Collections.Stack]::new()
  4. $stack.Push($tree)
  5. while ($stack.Count) {
  6. $node = $stack.Pop()
  7. if ($node.Left) {
  8. $stack.Push($node.Left)
  9. }
  10. if ($node.Right) {
  11. $stack.Push($node.Right)
  12. }
  13. ... # do something with the node
  14. }
  15. }
  16.  
  17. # recursive
  18. function traverse($tree)
  19. $tree.left, $tree.right | ? {$_} | % {traverse $_}
  20. ... # do something with the node
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement