Re: "Variable Depth" Problem
- From: Andrew Poelstra <apoelstra@xxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 06 Apr 2010 05:31:10 GMT
On 2010-04-05, none <none@xxxxxxxxx> wrote:
But how do you get a variable number of nested for-loops, or the logical
equivalent of that? I'm really just looking for general advice on how to
deal with variable-dimension arrays. In the past, I've run into the
problem only a handful of times, and in each case I was able to do
something that worked but was very un-elegant and required heavy
assumptions about what the nature of the array would be.
Thanks in advance.
Use recursion:
void recurse(my_array) {
for(elem in my_array)
recurse(elem);
}
You might need to add a check to see if you are at the deepest
possible depth, and do some actual work instead of just recursing
again, but that's the worst sort of hackery required in general.
--
Andrew Poelstra
http://www.wpsoftware.net/andrew
.
- References:
- "Variable Depth" Problem
- From: none
- "Variable Depth" Problem
- Prev by Date: Re: "Variable Depth" Problem
- Next by Date: Re: "Variable Depth" Problem
- Previous by thread: Re: "Variable Depth" Problem
- Next by thread: Re: #include "cpuid.os"
- Index(es):