Fixed issues with node state.

This commit is contained in:
z123 2016-05-08 11:22:47 -07:00
parent a18e0532b0
commit 4306797043
3 changed files with 8 additions and 8 deletions

View File

@ -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"
]
},
{

View File

@ -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)"
]
},

View File

@ -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"
]
},