Finding all paths from source to destination

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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);
}