Exemplo n.º 1
0
    def dfs(self, graph, s):
        stack = Stack_ResizingArray()
        stack.push(s)
        while stack:
            v = stack.pop()

            self.count_connected += 1
            print(v, self.count_connected)
            for neighbor in graph.adj[v]:
                if not self.marked_array[neighbor]:
                    self.marked_array[v] = True
                    stack.push(neighbor)
    def dfs(self, graph, v):
        self.marked_array[v] = True
        stack = Stack_ResizingArray()
        stack.push(v)
        while stack:
            vertex = stack.pop()

            neighbors_list = graph.adj[vertex]
            for i in neighbors_list:
                if self.marked_array[i] != True:
                    stack.push(i)
                    self.marked_array[vertex] = True
                    self.path_array[i] = vertex