GeeCON Prague 2014*
The moose likes Java in General and the fly likes Recursive Problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Recursive Problem." Watch "Recursive Problem." New topic
Author

Recursive Problem.

Jon Bud
Greenhorn

Joined: Jan 29, 2009
Posts: 12
So I've ended up changing the else's to if there by allowing the program to run through each case in effect. But, when I run this program the console window doesn't pop up. I'm sure that this is because the program is in sort of an infinite recursion type situation. I guess I have to some how have the return value of the method triggger the stoppage of the function so I don't get caught in a loop. I don't know how to do this though. Does anyone have any suggestions. Do I have to return true each time one of the if blocks is done calling the traverse method? Should I check if the space has been traversed already?

















Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
Do I have to return true each time one of the if blocks is done calling the traverse method? Should I check if the space has been traversed already?

The if-conditions are not sufficient for controlling the recursion. They should not evaluate to "true" if "board[ver][hor]" already has a value, because that would mean that the the field is about to be stepped on a second time.

So you need to initialize all the values of the board to some value that "count" can never take (maybe -1), and then check that value as part of the if-condition.

What do you mean calling "return true"?

That's actually not crucial, as long as the if conditions check for not stepping on a field a second time.


Ping & DNS - my free Android networking tools app
 
GeeCON Prague 2014
 
subject: Recursive Problem.