Finding Shortest Paths of weighted graph using stacks
As with most graph searching algorithms, you have to keep the state of each node during the searching. The state would have following values: white, gray, black with following interpretation:


white = node has not yet been discovered during the current search, or it is unreachable.
gray = node that was discovered, but not yet processed by the search algorithm.
black = reachable nodes in your graph, that the search algorithm has discovered and also processed.


This labeling ensures that you do not search in endless loops.

To get all shortest paths from a node s to another node e:


mark all nodes nodes as white.
then as you visit nodes you label them gray and put them on the stack.
If you processed all neighbours of a node, you label it black.
To recover all the shortest paths from s to e, you need to maintain an array, call it parents, i.e. parents(v) = u, meaning v was visited from u.


After you searched the whole graph, you proceed backwards from the end node e via the parents array, to get all the shortest paths from the starting node s.