Este objeto recorre arboles binarios en amplitud.
1 """
2 Funcionalidad: Recorre Arboles Binarios en amplitud.
3 Autor: Diego Andrés Sanabria Martín (diegueus9)
4 Fecha: Noviembre de 2005
5 """
6 class VisitanteAmplitudArbol:
7 def __init__(self):
8 self.abierto=[]
9 self.cerrado=[]
10 def amplitud(self, arbol):
11 self.abierto.append(arbol)
12 while len(self.abierto)!=0:
13 tmp=self.abierto.pop(0)
14 try:
15 self.cerrado.index(tmp)
16 except:
17 self.cerrado.append(tmp)
18 if tmp.izq!=None:
19 self.abierto.append(tmp.izq)
20 if tmp.der!=None:
21 self.abierto.append(tmp.der)
22 a=""
23 for i in self.cerrado:
24 a=a+str(i.clave)+","
25 return a
