Dynastie/tree.py

22 lines
451 B
Python

class TreeNode():
def __init__(self, key, value):
self.childs = []
self.key = key
self.value = value
def addChildNode(self, node):
self.childs.append(node)
def hasChilds(self):
return (len(self.childs) > 0)
def find(self, key):
if key == self.key: return self
for child in self.childs:
r = child.find(key)
if r != None: return r
return None