class Vertex():
def __init__(self, data=""):
self.data = data
self.children = []
def add(self, parent, child2):
if self.data == parent:
self.children.append(Vertex(child2))
else:
for child in self.children:
child.add(parent, child2)
def printTree(self, s = "---"):
print(s + self.data)
s = " " + s
for child in self.children:
child.printTree(s)
def preorder(self, s = []):
s.append(self.data)
for child in self.children:
child.preorder(s)
return s
def inorder(self, s = []):
if len(self.children) > 0:
self.children[0].inorder(s)
s.append(self.data)
if len(self.children) > 1:
for child in self.children[1:]:
child.inorder(s)
return s