scootermaster
Platinum Member
I know we all hate recursion -- well, those of use weened on C/C++ do. Those wackos who grew up on Lisp must love it! -- but I have a question that's been nagging at me that I can't seem to solve (and no, it's not for homework).
So I have this graph structure (it's a DAG; directed acyclic, for the rest of you) and I want to return a couple of values up "through" the recursion stack; that is to say, I want to do a DFS from a certain node, until I hit a pre-defined stopping point (in this case, either a "matching" node or the sink) and then return two values: the hop count from the start to finish, and the aggregate cost to get there.
I'm just having problems getting the recursive function to return the right value to it's preceding calls, and then having the preceding calls aggregate the totals correctly, etc (it's tough to figure out what needs to be passed in as a parameter to the recursive call, what can be local, what needs to be local, what has to be passed by reference, and what needs to be returned, since each call is going to have it's own copies of things, and of course, there's C's friend parameter passing semantics).
If you want more details about what I'm actually doing -- if you're into that sort of thing -- I can get into it.
Any ideas?
So I have this graph structure (it's a DAG; directed acyclic, for the rest of you) and I want to return a couple of values up "through" the recursion stack; that is to say, I want to do a DFS from a certain node, until I hit a pre-defined stopping point (in this case, either a "matching" node or the sink) and then return two values: the hop count from the start to finish, and the aggregate cost to get there.
I'm just having problems getting the recursive function to return the right value to it's preceding calls, and then having the preceding calls aggregate the totals correctly, etc (it's tough to figure out what needs to be passed in as a parameter to the recursive call, what can be local, what needs to be local, what has to be passed by reference, and what needs to be returned, since each call is going to have it's own copies of things, and of course, there's C's friend parameter passing semantics).
If you want more details about what I'm actually doing -- if you're into that sort of thing -- I can get into it.
Any ideas?