How do I construct a binary tree (not binary search tree) from a preorder listing in Python using only the built in list? Each node in the preorder listing also has a "flag" that shows if it's a leaf or internal node. And each node has 2 children (No 0 or 1 child)
I made a class to represent a Node
class Node:
def __init__(self, initType):
self.type = initType
self.leftChild = None
self.rightChild = None
I think I should use a stack here, but I don't want to import the stack library.
Solutions I found online are for BST only or the input consists of an inorder list and a preorder list, not just the preorder list alone.
listas a LIFO stack: use the.appendmethod to push an item onto the list and the.popmethod to pop it back off again.complete binary tree(with two nodes exactly), please edit your question to specify this.listthat acts as a LIFO stack?