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