递归函数-参数值在某个值之后不更新



我写了一个递归函数,指向integer的指针作为参数传递。这个整数值在函数中是递增的,但我面临着一个奇怪的问题,即在某个值之后,它的值永远不会更新。甚至我也在检查那个地址的值。

下面是代码:--

   computeWait(long long int begin, long long int begin2, long long int w,
    int* current, int limit)      
   {    
      long long int next = 0, arrival = 0;
      long long int next1 = 0, service = 0;
      long long int serviceTime = 0;
      long long int wait = 0;
      static long long int Ta = 0;
      static long long int Ts = 0;
      static long long int W = 0;
      while(*current < limit)
      {
         next = (16807 * begin) % m;
         arrival = -200 * log((double)next/m);
         next1 = (16807 * begin2) % m;
         service = -100 * log(EDRN((double)next1));
         wait = max(0, (w + service - arrival));
         Ta = Ta + arrival; 
         Ts = Ts + service; 
         W = W + wait;
         *current = *current + 1;;
         computeWait(next, next1, wait, current, limit);
       }   
       printf("nnTotal arrival %Ld Total service %Ld Total wait %Ldn", Ta/limit, Ts/limit, W/limit);
   }
   int main(int agrc, char* argv[])    
   {
       int num = 0;
       int currentValue = 0;        // seed number
       int end = 1000000;
       computeWait(1, 46831694, 0, &currentValue, end);          
   }

在103917之后,它的值没有得到更新,并且它给出了内存保护失败。

请让我知道我哪里做错了什么,因为修复它似乎很琐碎。

谢谢,尼哈。

嗯,我并没有真正尝试理解代码,但我看到了一些大数字和单词递归。所以我想这是堆栈溢出,因为你的递归太深了?

最新更新