关于尾递归

时间:2014-06-24 03:54:00

标签: c tail-recursion

最近我正在阅读使用c的掌握算法,在本书中我有1个练习,我无法用c实现。

Tn = 1             if n=1 ,
Tn = 2T(n/2) + n   if n > 1

任何人都可以帮助我吗?我会非常感激。

我试过了。

#include <stdio.h>

int test(int n) {
if (n == 1)
  return 1;
else if( n > 1 )
  return test(n / 2) * 2 + n;
}

int testtail(int n, int running_result) {
  if (n == 1)
    return running_result;
  else
    **return testtail(n / 2, ???? );** // How can I implement the second param
}

我很抱歉!我不是英语母语人士!也许我在语法上犯了一些错误!我应该为此道歉!

0 个答案:

没有答案
相关问题