示例#1
0
 def BFS(self):
     res = []
     q = CodaArrayList_deque()
     if self.root != None:
         q.enqueue(self.root)
     while not q.isEmpty():
         current = q.dequeue()
         res.append(current.info)
         for s in current.sons:
             q.enqueue(s)
     return res
示例#2
0
 def BFS(self):
     """Permette di restituire una lista di elementi ottenuta da una visita
     in ampiezza dell'albero."""
     res = []
     q = CodaArrayList_deque()
     if self.root != None:
         q.enqueue(self.root)
     while not q.isEmpty():
         current = q.dequeue()
         res.append(current.info)
         if current.leftSon != None:
             q.enqueue(current.leftSon)
         if current.rightSon != None:
             q.enqueue(current.rightSon)
     return res
示例#3
0
 def BFS(self):
     """Visita in ampiezza
     return: lista di BinaryNode.info"""
     res = []
     q = CodaArrayList_deque()
     if self.root != None:
         q.enqueue(self.root)
     while not q.isEmpty():
         current = q.dequeue()
         if self.isActive(current):
             res.append(current.info)
         if current.leftSon != None:
             q.enqueue(current.leftSon)
         if current.rightSon != None:
             q.enqueue(current.rightSon)
     return res