Finding all paths from source to destination
[cc lang=”cpp”]
stack node_stack;
set node_set;
AllPathFromSourceToDestination(node s, node d) {
node_stack.push(s);
node_set.add(s); //mark each node in the path
// for each node v that adjacent with node s:
for_each(node v, adjacent(v,s)) {
if(v == d) {
Output(node_stack);
} else {
if(node_set.has(v)==false) {
AllPathFromSourceToDestination(v, d);
}
}
}
node_set.del(s);
node_stack.pop(s);
}
[/cc]