| 246 | |
| 247 | |
| 248 | def postorder_itr(node): |
| 249 | # L R N |
| 250 | # 1. Push root to first stack. |
| 251 | # 2. Loop while first stack is not empty |
| 252 | # 2.1 Pop a node from first stack and push it to second stack |
| 253 | # 2.2 Push left and right children of the popped node to first stack |
| 254 | # 3. Print contents of second stack |
| 255 | s1, s2 = [node], [] |
| 256 | while s1 != []: |
| 257 | temp = s1.pop() |
| 258 | s2.append(temp) |
| 259 | if temp.left: |
| 260 | s1.append(temp.left) |
| 261 | if temp.right: |
| 262 | s1.append(temp.right) |
| 263 | print(*(s2[::-1])) |
| 264 | |
| 265 | |
| 266 | def bst_frm_pre(pre_list): |