S
Scott Dabot
Im trying to print out the order in which the vertexes of a graph are
pushed on to the stack then print out the order in which they are popped
off the stack. My current approach is
void dfs(struct ADJACENCY *G_adj,int v)
{
int i,u;
G_adj->mark[v]=1;
visit(v,G_adj);
while ((u=next_adj_vertex(v,G_adj))>=0) {
if (G_adj->mark==0)
{
dfs(G_adj,u);
}
}
visit(v,G_adj);
}
int visit(int v, struct ADJACENCY *G_adj)
{
printf("%c ", G_adj->vertexlabel[v]);
return v;
}
With this approach the order in which my graph should print out should
be A, B, D, E , C , F ( order in which its pushed) ... but by me adding
the visit function to the end of the dfs call , im trying to print out
the order in which its popped off ... and thus i get this:
pushed: a b d e , then popped: e d b pushed: c f popped f c popped: a
which way could i reprogram this so that it prints out pushed: a b d e c
f , popped f c e d b a ?????????
pushed on to the stack then print out the order in which they are popped
off the stack. My current approach is
void dfs(struct ADJACENCY *G_adj,int v)
{
int i,u;
G_adj->mark[v]=1;
visit(v,G_adj);
while ((u=next_adj_vertex(v,G_adj))>=0) {
if (G_adj->mark==0)
{
dfs(G_adj,u);
}
}
visit(v,G_adj);
}
int visit(int v, struct ADJACENCY *G_adj)
{
printf("%c ", G_adj->vertexlabel[v]);
return v;
}
With this approach the order in which my graph should print out should
be A, B, D, E , C , F ( order in which its pushed) ... but by me adding
the visit function to the end of the dfs call , im trying to print out
the order in which its popped off ... and thus i get this:
pushed: a b d e , then popped: e d b pushed: c f popped f c popped: a
which way could i reprogram this so that it prints out pushed: a b d e c
f , popped f c e d b a ?????????