0
点赞
收藏
分享

微信扫一扫

[DnA] BFS 和 DFS的伪代码

火热如冰 2022-09-23 阅读 79
前端开发


DFS:

def DFS(node,value):
if not node:
return
for ele in node.所有邻居:
if not ele.ischecked: #避免重复检查
ele.ischecked == True #避免重复检查
if ele.value == value:
result.append(ele)
else:
DFS(ele,value)

BFS:

result = []
def BFS(node,value):
nextlist = node.所有邻居
for ele in nextlist:
if not ele.ischecked:
ele.ischecked = True
if ele.value == value:
return ele
else:
把ele的所有邻居append到nextlist中
nextlist.pop() #把当前ele从nextlist中弹出

举报

相关推荐

DFS与BFS伪代码

bfs和dfs

BFS和DFS

DFS和BFS

python dfs和bfs

DFS和BFS简述

BFS/DFS

BFS搜索和DFS搜索

0 条评论