#include #define MAX 4 /* 42 second */ struct ss { int val; struct ss *next; }; typedef struct ss s_node; typedef s_node *link; link stack=NULL; int stacksize() { link top; int i; top=stack; i=0; while (top != NULL) { i++; top=top->next; } return i; } void push(int k) { link kk; kk=(link)malloc(sizeof(s_node)); kk->next=stack; kk->val=k; stack=kk; } void pop(int *k) { link top; if (stack != NULL) { *k=stack->val; top=stack; stack=stack->next; free(top); } } void main() { int n,m,ans,k1,k2,kk; clrscr(); printf("give me ackerman 1st and 2nd parameter --> "); scanf("%d %d",&m,&n); if ((m < 0) || (n < 0)) printf("cannot compute ackerman!!!\n"); else { /* m>=0 && n>=0 */ push(m); push(n); k1=m; k2=n; while ((kk=stacksize()) != 1) { pop(&n); pop(&m); /* printf("m=%d n=%d\n",m,n); getche(); */ if (m == 0) push(n+1); else if (n == 0) { push(m-1); push(1); } else { push(m-1); push(m); push(n-1); } } /* while */ pop(&ans); printf("ackerman(%d,%d)=%d\n",k1,k2,ans); getche(); } }