xblade
April 6th, 2008, 07:52 AM
I need to create a depth first traversal structure in psuedocode and below is what i have come up with:
GraphSearch(G,v,u)
G Graph being searched
v Node at the start of the search.
n Node being searched for
visit(v)
mark(v) as visited
putstack(v)
putarraylist(v) // Will add the node visited to the ArrayList
while stack is not empty
getstack(x)
for all edges x > w in G
if w is not marked then
GraphSearch(G,w,u)
end if
if w = u return w
end for
end while
return 0
Im wondering if this is the right code for depthsearch or will there be a fault somewhere inside. ?
GraphSearch(G,v,u)
G Graph being searched
v Node at the start of the search.
n Node being searched for
visit(v)
mark(v) as visited
putstack(v)
putarraylist(v) // Will add the node visited to the ArrayList
while stack is not empty
getstack(x)
for all edges x > w in G
if w is not marked then
GraphSearch(G,w,u)
end if
if w = u return w
end for
end while
return 0
Im wondering if this is the right code for depthsearch or will there be a fault somewhere inside. ?