diff options
Diffstat (limited to 'arbol.py')
-rw-r--r-- | arbol.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/arbol.py b/arbol.py new file mode 100644 index 0000000..7abcbe0 --- /dev/null +++ b/arbol.py @@ -0,0 +1,26 @@ +class Nodo: + def __init__(self, dato = None): + self.dato = dato + self.hijos = [] + + def print(self, n = 0): + s = ' ' * n + 'Nodo:' + "\n" + s += ' ' * n + "dato = " + str(self.dato) + "\n" + s += ' ' * n + "hijos =\n" + for h in self.hijos: + s += h.print(n + 1) + s += "\n" + return s + + def __str__(self): + return self.print() + + +class Arbol: + def __init__(self, raiz: Nodo = Nodo()): + self.raiz = raiz + + def __str__(self): + if self.raiz: + return str(self.raiz) + return "None" |