Help with Recursion
I need to implement a recursive function to compute the number of 0 that are next to another 0.
A data file is read into an array, and looks something like this:
111111111111111
100110011010001
110010000011101
111011110001101
111000111011111
111001100000111
111111111111111
This is the section where i''m think the recursion need to go?
void AreaCal()
{
if ((Grid[Row][Col] == ''1'') || (Grid[Row][Col] == ''²''))
Area = 0;
else
{
Grid[Row][Col] = ''²'';
Area ++;
}
}
This section takes the coordinates entered in by user and check to see if the coordinates contains a 0 or 1. If it contains a 0 then it replace the 0 with ASCII value 178. I have an ideal on how to implement the recursion, just not sure how to code it out to make it work. Any suggestion?
Try something similar to this:
This should hopefully, work, but might have a bug or two. You need to remember with recursion to always have a terminating case (in this situation, it is if you are out of bounds of the array or on a non-''0'' space).
Be sure to let me know what grade I get on this assignment.
|
This should hopefully, work, but might have a bug or two. You need to remember with recursion to always have a terminating case (in this situation, it is if you are out of bounds of the array or on a non-''0'' space).
Be sure to let me know what grade I get on this assignment.
![](wink.gif)
that looks too much like a homework problem to me.
b/c i remember doing something similar when i was in my first semester of c++
"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
b/c i remember doing something similar when i was in my first semester of c++
"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
quote:
Original post by jaxson
Try something similar to this:
|
This should hopefully, work, but might have a bug or two. You need to remember with recursion to always have a terminating case (in this situation, it is if you are out of bounds of the array or on a non-''0'' space).
Be sure to let me know what grade I get on this assignment.
![](wink.gif)
Thanks Jaxson for you input, got me through coder''s block. lol
|
Now I just have to debug one little bug. Thanks for your help
quote:
Original post by jaxson
Try something similar to this:
|
This should hopefully, work, but might have a bug or two. You need to remember with recursion to always have a terminating case (in this situation, it is if you are out of bounds of the array or on a non-''0'' space).
Be sure to let me know what grade I get on this assignment.
![](wink.gif)
Thanks Jaxson for you input, got me through coder''s block. lol
|
Now I just have to debug one little bug. Thanks for your help
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement