如何为具有两个递归函数的递归函数编写堆栈?

时间:2021-01-14 17:17:25

标签: c++ c++11 recursion stack

我遇到了一个包含两个递归函数的问题。我无法理解其背后的循环和堆栈机制。这是我程序的代码行。

#include<iostream>

using namespace std;

int test(int num)
{   
    if (num != 0)
    {
        num = num - 1;
        test(num);
        cout << num << " ";
        test(num);
    }
}

int main()
{
    test(3);
}

这是程序的输出

  0 1 0 2 0 1 0

谁能用堆栈解释这个程序的输出?

0 个答案:

没有答案
相关问题