int ackermann2(int m, int n) {
if (m < 0 || n < 0) {
return -1;
}
stack<ack> st;
int f=0;
st.push(ack(m, n, 0));
while (!st.empty()) {
if (st.top().m == 0) {
st.top().ret = st.top().n + 1;
}
else if (st.top().n == 0) {
st.top().n = 1;
st.top().m--;
}
else {
st.push(ack(st.top().m--, st.top().n - 1,0));
}
if (st.top().ret != 0) {
int tmp = st.top().ret;
st.pop();
st.top().n = tmp;
f = tmp;
}
}
return f;
}
C++算法 数据结构 非递归实现阿克曼函数,出错了,问题在哪
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-