예제 #1
0
파일: graph.py 프로젝트: gmarciani/ipath
 def dfs(self, root_node_id):
     """
     Returns the LIFO path-as-list from graph's root to all other nodes in graph.
     
     dfs(root_node_id) -> path
     
     @type root_node_id: integer
     @param root_node_id: graph's root's id.
     
     @rtype: list
     @return: LIFO path from graph's root to all other nodes in graph.
     """
     try: 
         status = dict.fromkeys(self._nodes.iterkeys(), 0)
         status[root_node_id] = 1            
         L = []        
         s = Stack()
         s.push(root_node_id)            
         while not s.is_empty():
             curr_node_id = s.pop()
             status[curr_node_id] = -1
             L.append(self._nodes[curr_node_id])
             arcs_set = self._inc[curr_node_id]
             for arc in arcs_set:
                 if status[arc._head] is 0:
                     status[arc._head] = 1
                     s.push(arc._head)
         return L
     except KeyError:
         return []       
예제 #2
0
파일: tree.py 프로젝트: gmarciani/pymple
 def dfs(self):
     """
     Returns the LIFO path-as-list from the root to all other nodes inside tree. 
     
     dfs() -> reasearch_path
     
     @rtype: list
     @return: LIFO path-as-list from the root to all other nodes inside tree.
     """
     res = []
     stack = Stack()
     if self._root_id is not None:
         stack.push(self._root_id)
     while not stack.is_empty():
         current_id = stack.pop()
         res.append(current_id)
         sons = self._get_sons(current_id)
         for son_id in sons:
             stack.push(son_id)
     return res