N
nooneinparticular314159
I'm doing a depth first search and want to record the least cost path
as I traverse the graph. I create an arraylist. I want to add things
to teh arraylist in a recursive call to teh function where teh
arraylist is created. When the recursion returns, the original
arraylist should be unchanged, but I should be able to return a copy of
the new arraylist with all the changes made.
For some reason, I can't get this to work. If I pass in the arraylist
each time, I wind up with an arraylist with ALL paths recorded on it,
which is not what I want. If I create a new arraylist inside my
recursive method, I am unable to build on the original. I want each
recursion to add on the new nodes on the path, and to return the path
if it reaches the destionation. But I need to iterate over all
possible branches from each node, so I don't want to destroy the state
of the original before each recursive call. Any idea what I can do?
Thanks!
as I traverse the graph. I create an arraylist. I want to add things
to teh arraylist in a recursive call to teh function where teh
arraylist is created. When the recursion returns, the original
arraylist should be unchanged, but I should be able to return a copy of
the new arraylist with all the changes made.
For some reason, I can't get this to work. If I pass in the arraylist
each time, I wind up with an arraylist with ALL paths recorded on it,
which is not what I want. If I create a new arraylist inside my
recursive method, I am unable to build on the original. I want each
recursion to add on the new nodes on the path, and to return the path
if it reaches the destionation. But I need to iterate over all
possible branches from each node, so I don't want to destroy the state
of the original before each recursive call. Any idea what I can do?
Thanks!