We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f196f72 commit 94b836bCopy full SHA for 94b836b
.gitignore
@@ -6,3 +6,4 @@ dist/
6
.coverage
7
coverage.xml
8
.pytest_cache/
9
+.vs/
algoritms/dfs_iterative.py
@@ -0,0 +1,24 @@
1
+"""Implementation iterative depth-first search."""
2
+
3
4
+def dfs_iterative(graph):
5
+ """Visit all the vertex of graph.
+ Args:
+ graph: graph for search
10
+ Returns:
11
+ visited (dict): key (vertex id), value (true if vetrex is visited)
12
+ """
13
+ visited = {vertex : False for vertex in graph}
14
15
+ stack = []
16
+ for vertex in graph:
17
+ stack.append(vertex)
18
19
+ while len(stack) > 0:
20
+ vertex = stack.pop()
21
+ for adjacent_vertex in vertex:
22
+ if visited[adjacent_vertex] is False:
23
+ stack.append(adjacent_vertex)
24
+ visited[adjacent_vertex] == True
0 commit comments