| 222 | |
| 223 | |
| 224 | def inorder_itr(node): |
| 225 | # L N R : Left, Node, Right |
| 226 | # 1) Create an empty stack S. |
| 227 | # 2) Initialize current node as root |
| 228 | # 3) Push the current node to S and set current = current->left until current is NULL |
| 229 | # 4) If current is NULL and stack is not empty then |
| 230 | # a) Pop the top item from stack. |
| 231 | # b) Print the popped item, set current = popped_item->right |
| 232 | # c) Go to step 3. |
| 233 | # 5) If current is NULL and stack is empty then we are done. |
| 234 | stack = [] |
| 235 | current = node |
| 236 | while True: |
| 237 | if current != None: |
| 238 | stack.append(current) # L |
| 239 | current = current.left |
| 240 | elif stack != []: |
| 241 | temp = stack.pop() |
| 242 | print(temp.info) # N |
| 243 | current = temp.right # R |
| 244 | else: |
| 245 | break |
| 246 | |
| 247 | |
| 248 | def postorder_itr(node): |