Complete the function ‘find_path_dfs()’ which finds cost of going from the source vertex (src) to destination vertex (dst) using Depth First Search (DFS) algorithm. Use stack for implementing DFS algorithm.
void find_path_dfs(int * graph, int size, int src, int dst)
{
int visited[size] ={0};
struct node * top =NULL; //Make a stack for holding the visited vertices
int crnt_visiting =src;
int crnt_exploring =src;
int path_cost =0;
bool PATH_FOUND =false;
while(!PATH_FOUND)
{
visited[crnt_visiting] =1;
struct element temp;
if(crnt_visiting==dst) //If the vertex is found
{
printf("\nPath found: ");
printf("\nCost: %d\n", path_cost);
while(!isStackEmpty(&top))
{
printf("Pop\n");
pop(&top);
}
PATH_FOUND=true;
continue;
}
else //Explore this vertex
{ //Complete this function. You are free to make any changes to this function. Make sure that path cost is correctly found.
}}}
Comments
Leave a comment