views:

250

answers:

2

I implemented a depth-first-search in c# based on information I found on the net and old java books and I used the Node and NodeList and Graph from the msdn site. How can one modify the DFS or BFS to check for particular weight?

+2  A: 

To implement a DFS, you need to use a stack implicit (recursively call the function itself) or explicit (use a stack object). For each state, you have a current node you are visiting. You will have to visited each neighbor of the current node, and also if you have visited the current node, then you can skip processing the current one.

That is pretty much the algorithm. What you need to do is translating that to code.

leiz
I already have that.., I just need to check if path exisits
the path exists as long as you reach to that node from a starting node
leiz
@leiz - well, yes and no, let's say path exisits from A to D, but you want to see if there's a path from A to D via C (e.g. A-C-D).
+3  A: 

If you can find a path from A-C and a path from C-D then you have your path A-C-D.

Carles
right, i know that..I'm just having trouble figuring out simple loop..
never mind, i got it