mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Fixed issues with node state.
This commit is contained in:
parent
a18e0532b0
commit
4306797043
|
@ -116,14 +116,14 @@
|
|||
" return\n",
|
||||
" queue = deque()\n",
|
||||
" queue.append(root)\n",
|
||||
" root.visited = True\n",
|
||||
" root.visit_state = State.visited\n",
|
||||
" while queue:\n",
|
||||
" node = queue.popleft()\n",
|
||||
" visit_func(node)\n",
|
||||
" for adjacent_node in node.adjacent:\n",
|
||||
" if not adjacent_node.visited:\n",
|
||||
" if adjacent_node.visit_state == State.unvisited:\n",
|
||||
" queue.append(adjacent_node)\n",
|
||||
" adjacent_node.visited = True"
|
||||
" adjacent_node.visit_state = State.visited"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -110,9 +110,9 @@
|
|||
" if root is None:\n",
|
||||
" return\n",
|
||||
" visit_func(root)\n",
|
||||
" root.visited = True\n",
|
||||
" root.visit_state = State.visited\n",
|
||||
" for node in root.adjacent:\n",
|
||||
" if not node.visited:\n",
|
||||
" if node.visit_state == State.unvisited:\n",
|
||||
" dfs(node, visit_func)"
|
||||
]
|
||||
},
|
||||
|
|
|
@ -127,7 +127,7 @@
|
|||
" return True\n",
|
||||
" queue = deque()\n",
|
||||
" queue.append(start)\n",
|
||||
" start.visited = True\n",
|
||||
" start.visit_state = State.visited\n",
|
||||
" while queue:\n",
|
||||
" node = queue.popleft()\n",
|
||||
" if node is None:\n",
|
||||
|
@ -135,9 +135,9 @@
|
|||
" if node is end:\n",
|
||||
" return True\n",
|
||||
" for adj_node in node.adjacent:\n",
|
||||
" if not adj_node.visited:\n",
|
||||
" if adj_node.visit_state == State.unvisited:\n",
|
||||
" queue.append(adj_node)\n",
|
||||
" adj_node.visited = True\n",
|
||||
" adj_node.visit_state = State.visited\n",
|
||||
" return False"
|
||||
]
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user