
本文共 3302 字,大约阅读时间需要 11 分钟。
���������������������Depth-First Search, DFS������������������������������������������������������������������������������������������������������������������������������������������������������������������������������DFS������������������������������������������������������������������������������������������������������
���������V���������������������������
������������������������������������Dfs(V)
������������������������V���������������������������������������������������������
���������������������������������V���������������������������������������������������������������������������������V���������������������������������"������"������������������������������������������������
������������������������������V������������������������"������"������������������������������
���������������������������V���������������������U���������������������������������U������������������������������������
������������������������������������������������������������������������������
������������
������������������������������������������������������������������������������������������������������
���������������������������������������path[MAX_LEN]
���������MAX_LEN
���������������������������������������������
������������������������������������������������������������������������������depth
������������������������������������������������������������������path[depth]
���������������depth
���
���������������������������������������������������������������������������path[depth]
���������������������������������������������������������depth
������������������������������
������������������
���������DFS���������������������������������������������������������������������������������������G
���������������������
G[i][j]
������������i���������j���������������������������������������������������������false
���- ���������������������������
G
���������������������������������������������
������������
bool Dfs(V) { if (V == termination_node) // ��������������������������������������� return true; if (V == visited_node) // ������������������������������������������������ return false; visited_nodes.add(V); // ������������������������������ for (each neighboring node U of V) { if (Dfs(U)) // ������������DFS(U) return true; } visited_nodes.remove(V); // ��������������������������� return false;}
������������
������������������������������������������������������������������
int depth = 0;Node path[MAX_LEN]; // MAX_LEN������������������������bool Dfs(V) { if (V == termination_node) { path[depth] = V; return true; } if (V == visited_node) return false; visited_nodes.add(V); path[depth] = V; depth++; for (each neighboring node U of V) { if (Dfs(U)) // ������������ return true; } depth--; visited_nodes.remove(V); return false;}
������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������DFS���������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
