View Single Post

April 24th, 2005, 11:41 AM
planoie
Friend of Wrox
 Points: 16,481, Level: 55
 Activity: 0%

Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

Here's my logic:

We start with your set of information. It exists as a jagged array which is an array of arrays (versus a 2 dimensional array which is a single array representing a square matrix).
Code:
```      | Item1   Item2   Item3
------+----------------------
Set 1 | Red     Yellow  Blue
Set 2 | 8       9
Set 3 | Covered```
We make the initial call to the recursing function telling it "start spinning thru all the elements in ONE set, starting at the first set".
The 0 in the second argument is what tells it to start at the first element, or element 0 in the main array. Then the recursive function adds the string of the current position in the process (set 1, item 1) to the line. Then it checks to see if there are more sets to deal with and it calls the recursive function to dive into the next set. When a recursion call returns, the function moves on to the next item in the set that it is dealing with.

Here's what the process looks like from the perspective of the set/item positions and what happens at each position.
Code:
```[start process] (recurse into set 1)
Red             (recurse into set 2)
- 8           (recurse into set 3)
- Covered   [end of sets, no action]
- 9           (recurse into set 3)
- Covered   [end of sets, no action]
Yellow          (recurse into set 2)
- 8           (recurse into set 3)
- Covered   [end of sets, no action]
- 9           (recurse into set 3)
- Covered   [end of sets, no action]
Blue            (recurse into set 2)
- 8           (recurse into set 3)
- Covered   [end of sets, no action]
- 9           (recurse into set 3)
- Covered   [end of sets, no action]```
Hope this makes sense to you. Wrapping your head around recursive logic can be tricky if you haven't worked with it.

-Peter