This is an assignment, so don't help me too much.
We have to write a recursive method that accepts 1 int and outputs this when given '4':
QUOTE
Enter rabbit: n=4
Enter rabbit: n=3
Enter rabbit: n=2
Leave rabbit: n=2 value=1
Enter rabbit: n=1
Leave rabbit: n=1 value=1
Leave rabbit: n=3 value=2
Enter rabbit: n=2
Leave rabbit: n=2 value=1
Leave rabbit: n=4 value=3
Conceptually I think that it is supposed to:
(1.) Output all rabbits from itself to 1
(2.) Have the rabbit directly below the one calling it do (1.)
(3.) Display the recursive level of the rabbit in the tree when it leaves (finishes doing (2.))
I'd show you the code I've come up with, but it's just 15 pathetic lines that I've poured half a dozen hours into and don't even do (1.) anymore ever since I tried to make them do 2 & 3. Just know that I have put a bunch of thought into this problem, I'm probably over complicating it in my head, and I'm on narcotics (hydrocodone) because of 3 root canals I just got done and so my brain isn't cooperating with my will to solve this problem.
I think I can figure out (1.) and (2.), but (3.) seems more enigmatic. Maybe it will be easier to grasp once I have (1.) and (2.) working?
I guess my main question is whether or not you agree that a program that does (1.), (2.), and (3.) will satisfy the requirements, and whether or not you have any suggestions on improving (1.), (2.), and (3.) or implementing them.
Thank you.
This new version sort of does (1.) and (3.), but (2.) is still at large.
CODE
public int recursive(int r){
if( r == 0) { return 0; }
else{
System.out.println("Enter rabbit: n=" + r);
recursive( r - 1);
}
System.out.println("Leave rabbit: n=" + r + " value=" + counter);
counter++;
return 0;
}
This post has been edited by tex1ntux: 17 Feb, 2008 - 02:06 AM