1 / 3
Jun 2010

First code.

#include <iostream>
using    namespace std;
void f(int k) 
{  
     if (k==100000) 
     { cout << a << endl; return; } 
     f(k+1); } 
int main() 
{ 
    int a = 1;
    freopen("out.txt","w",stdout); 
    f(1); 
    return 0; 
}

Second code.

#include <iostream>
using    namespace std;
void f(int k) 
{  
     int a = 1;
     if (k==100000) 
     { cout << a << endl; return; } 
     f(k+1); } 
int main() 
{ 
    freopen("out.txt","w",stdout); 
    f(1); 
    return 0; 
}

the second code gives stack over flow error .
Can anyone explain me how to modify stack memory ?

  • created

    Jun '10
  • last reply

    Jun '10
  • 2

    replies

  • 169

    views

  • 2

    users

Stack size is controlled by the architecture of the machine that the code is being executed on. It can't be modified on SPOJ.

You might want to look into how the stack works with function calls.

A better method is to avoid recursion if possible. In your case, you could write a single for loop to perform the same operation.

My program uses a DFS function zzz.
I'll uses a BFS insteed of it.
Thanks you alot.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 14 6d

Want to read more? Browse other topics in C and C++ or view latest topics.