26 lines
660 B
Python
Executable File
26 lines
660 B
Python
Executable File
from stack import Stack
|
|
|
|
routes = []
|
|
|
|
|
|
def dfs(g, startPoint, adj, nodesNum):
|
|
print(adj)
|
|
route = ""
|
|
stack = Stack(nodesNum)
|
|
stack.push(startPoint)
|
|
visited = set()
|
|
visited.add(startPoint)
|
|
while stack.size() > 0:
|
|
vertex = stack.pop()
|
|
route += vertex + "->"
|
|
nodes = adj[vertex]
|
|
for node in nodes:
|
|
if node == '结束':
|
|
route += "结束"
|
|
routes.append(route)
|
|
route = route[:-2]
|
|
if node not in visited and node != "结束":
|
|
stack.push(node)
|
|
visited.add(node)
|
|
return routes
|