递归问题,无处下手啊,求指导
试编写如下定义的递归函数的递归算法,并根据算法画出求g(5,2)时栈的变化过程。g(m,n)=0 m=0,n>=0
g(m-1,2n) m>=0,n>=0
自知这块学的不好,无从下手啊
int g(int m, int n) { static int callIndex = 1; if (m == 0 && n >= 0) { //基本情况 cout << "调用次序" << callIndex++ << " m = " << m << " n = " << n << endl; return 1; } else if (m >= 0 && n >= 0) { //递归 cout << "调用次序" << callIndex++ << " m = " << m << " n = " << n << endl; return g(m - 1, 2 * n); } else { //输入不合理的情况 return -1; } }