def bfs(self): """ Returns the FIFO path-as-list from the root to all other nodes inside tree. bfs() -> reasearch_path @rtype: list @return: FIFO path-as-list from the root to all other nodes inside tree. """ res = [] queue = Queue() if self._root_id is not None: queue.enqueue(self._root_id) while not queue.is_empty(): current_id = queue.dequeue() res.append(current_id) sons = self._nodes[current_id]._sons for son_id in sons: queue.enqueue(son_id) return res
def __repr__(self): queue = Queue() queue.enqueue(self._root) queue.enqueue(None) s = "{" while not queue.is_empty(): currNode = queue.dequeue() if currNode is not None: s += str(currNode) if not currNode._sons.is_empty(): recordSon = currNode._sons.get_first_record() while recordSon is not None: queue.enqueue(recordSon.element) recordSon = recordSon._next queue.enqueue(None) else: s += "\n" s += "}" return s