I'm trying to find all paths between a starting vertex and an ending vertex using an adjacency matrix. My graph is unweighted & undirected.
I was trying to follow this algorithm but, I got stuck at the for each part.
Algorithm:
procedure FindAllPaths(u, dest)
{
push u to stack;
if(u == dest)
{
print stack;
}
else
{
foreach v that is adjacent with u and not in stack now
{
FindAllPaths(v, dest);
}
}
pop from stack;
}
My code:
void AdjacencyMatrix :: Find_All_Paths(int Origin, int Destination)
{
/*
MATRIX:
0 1 0 1 1
0 1 0 1 1
0 0 0 1 0
0 1 1 1 0
1 1 0 1 1
*/
//Push Origin to stack
Push_Vertex.push(Origin);
//Determine if Origin == Destination, if so, print the stack
if(Origin == Destination)
{
while(!Push_Vertex.empty())
{
cout << Push_Vertex.top() << " ";
Push_Vertex.pop();
}//while
cout << endl;
}//if
else
}//Find_All_Paths()