D
Daniel Pitts
Lets make this iterative, shall we?The code likes:
void fun(Array a){
for(int i=0; i<MAX; i++){
....
if(a != -1) {
a = -1; i = 0;
}
}
}
There you go, problem solved.
Lets make this iterative, shall we?The code likes:
void fun(Array a){
for(int i=0; i<MAX; i++){
....
if(a != -1) {
a = -1; i = 0;
}
}
}
The code likes:
Lets make this iterative, shall we?
void fun(Array a){
for(int i=0; i<MAX; i++){
....
if(a != -1) {
a = -1; i = 0;
}
}
}
There you go, problem solved.
Lets make this iterative, shall we?void fun(Array a){
for(int i=0; i<MAX; i++){
....
if(a != -1) {
a = -1; i = 0;
}
}
}
There you go, problem solved.
It is different to:
void fun(Array a){
for(int i=0; i<MAX; i++){
....
if(a != -1) {
a = -1;
fun(a);
}
}
}
The code likes:
Lets make this iterative, shall we?
void fun(Array a){
for(int i=0; i<MAX; i++){
....
if(a != -1) {
a = -1; i = 0;
}
}
}
There you go, problem solved.
Lets make this iterative, shall we?[email protected] said:void fun(Array a){
for(int i=0; i<MAX; i++){
....
a = ...;
fun(a);
}
}
Here, "Array a" will updated each time and I need "Array a" keeps
previous status, so dynamic allocation for "Array a" does not work.
What is your stop condition? It looks like infinite recursion to me..
The code likes:
void fun(Array a){
for(int i=0; i<MAX; i++){
....
if(a != -1) {
a = -1; i = 0;
}
}
}
There you go, problem solved.
It is different to:
void fun(Array a){
for(int i=0; i<MAX; i++){
....
if(a != -1) {
a = -1;
fun(a);
}
}
}
The only difference that I can see is that it doesn't process "-1" so
many times. Without knowing more semantics of the application, I can't
tell you if that works or doesn't work. Can you enlighten us on what
this function is supposed to actually do?
The only difference that I can see is that it doesn't process "-1" so
many times. Without knowing more semantics of the application, I can't
tell you if that works or doesn't work. Can you enlighten us on what
this function is supposed to actually do?
joseph said:The code likes:What is your stop condition? It looks like infinite recursion to me..
void fun(Array a){
for(int i=0; i<MAX; i++){
....
if(a != -1) {
a = -1;
fun(a);
}
}
}
Well..that's interesting. It looks like fun(a) should be called 2^MAX
- 1 times, but any one branch is only "MAX" deep.
So, that would mean that if you are running out of stack (because maxprogram will never complete trying to do 2^100 - 1 function calls.100, say) then this is only a small part of your problem, since your
(At least not within a few quadrillion years)
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.