Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Recursion-related problem

Reply
Thread Tools

Recursion-related problem

 
 
kelvSYC
Guest
Posts: n/a
 
      11-18-2003
I have a method that says something like this:

void foo(int b) {
// Do stuff and calculate the value of condition and anotherInt
if (condition) {
foo(anotherInt);
}
}

How can I change foo so that the inner foo is called only when the
outer foo is completed (ie. only one foo method is running)?

--
I am only a mirage.
 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      11-18-2003
kelvSYC wrote:
> void foo(int b) {
> // Do stuff and calculate the value of condition and anotherInt
> if (condition) {
> foo(anotherInt);
> }
> }
>
> How can I change foo so that the inner foo is called only when the
> outer foo is completed (ie. only one foo method is running)?


By elimination the recursion. How that can be done (and whether it can be done
at all) depends on the algorithm in question.

Basically, you need to replace the recursion with a loop, initialize the data
beforehand and then run the loop until the termination condition is met.

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      11-18-2003
kelvSYC wrote:
>
> I have a method that says something like this:
>
> void foo(int b) {
> // Do stuff and calculate the value of condition and anotherInt
> if (condition) {
> foo(anotherInt);
> }
> }
>
> How can I change foo so that the inner foo is called only when the
> outer foo is completed (ie. only one foo method is running)?


void foo(int b) {
do {
// Do stuff and calculate the value of condition and anotherInt
b = anotherInt;
} while (! condition);
}


--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments