Skip to content

Instantly share code, notes, and snippets.

@veryjos
Created November 27, 2017 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veryjos/851e992b7e1d754050b581e65b14a3e1 to your computer and use it in GitHub Desktop.
Save veryjos/851e992b7e1d754050b581e65b14a3e1 to your computer and use it in GitHub Desktop.
Print
/
Add
/ \
1 4
Start at print node, postorder traversal:
| Node: Print
|
| Visit left
| | Node: Add
| |
| | Visit left
| | | Node: 1
| | |
| | | stack.push(1)
| |
| | Visit right
| | | Node: 4
| | |
| | | stack.push(4)
| |
| | RighthandValue = stack.pop()
| | LefthandValue = stack.pop()
| |
| | Push RighthandValue + LefthandValue
|
| ValueToPrint = stack.pop()
| Print(ValueToPrint)
|
| Visit Right
end traversal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment