相关疑难解决方法(0)

这是尾递归吗?

我试图找到尾递归的例子,我真的没有看到常规和尾部之间的区别.如果这不是尾递归,有人可以告诉我为什么不是?

public static long fib(long index) {

// assume index >= 0

if (index == 0) // Base case

  return 0;

else

  if (index == 1) // Base case

    return 1;

  else

    // Reduction and recursive calls

    return fib(index - 1) + fib(index - 2);

}  // end of method fib(long index)
Run Code Online (Sandbox Code Playgroud)

java recursion computer-science tail-recursion fibonacci

4
推荐指数
1
解决办法
5518
查看次数