ACK函数:
image
非递归表示方式(C语言)
#include <stdio.h>
#define M 1000
#include<stdio.h>
//非递归解法
#define M 1000
int ACK(int m, int n)
{
int STACK[M], top = 0;
STACK[top] = m;
STACK[top + 1] = n;
while (top >= 0)
{
if (STACK[top] > 0)
{
if (STACK[top + 1] > 0)
{
STACK[top + 2] = STACK[top + 1] - 1;
STACK[top + 1] = STACK[top];
STACK[top] = STACK[top++] - 1;
}
else {
STACK[top] = STACK[top - 1];
STACK[top + 1] = 1;
}
}
else {
STACK[top] = STACK[top + 1] + 1;
top--;
}
}
return STACK[0];
}
int main()
{
int res = ACK(1, 0);
printf("%d", res);
return 0;
}
详细分析晚上回来再补