⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 阿克曼函数.cpp

📁 阿克曼函数
💻 CPP
字号:
#include<iostream.h>
#define m 300
class T			//****定义一个类
{
private:
	int a;
	int b;
	int c;
public:
	friend void PUSH(T*s,int a,int b,int c,int &top);
	friend void POP(T*s,int &a,int &b,int &c,int &top);
};
void PUSH(T*s,int a,int b,int c,int &top)       //*****入栈
{
	if(top==m)
	{	cout<<"stack-overflow"<<endl;return;	}
	top=top+1;
	s[top-1].a=a;
	s[top-1].b=b;
	s[top-1].c=c;
	return;
}
void POP(T*s,int &a,int &b,int &c,int &top)		//*****出栈
{
	if(top==0)
	{	cout<<"stack-underflow"<<endl;return;	}
	top=top-1;
	a=s[top].a;
	b=s[top].b;
	c=s[top].c;
	return;
}
void main()				//****主函数
{
	int top=0;
	int a,b,c,t;
	T*s;
	s=new T[m];            //长度为m的栈
	cout<<"请输入abc"<<endl;
	cin>>a>>b>>c;
	PUSH(s,a,b,c,top);
	while(top!=0)
	{
		POP(s,a,b,c,top);
		if((a!=0)&&(c!=0))
		{
			PUSH(s,a,b,c,top);
			PUSH(s,a,b,c-1,top);
		}
		else
		{
			if(a==0)	t=b+1;
			else
			{
				if(a==1) t=b;
				else if(a==2) t=0;
				else if(a==3) t=1;
				else t=2;
			}
			if(top!=0)
			{
				POP(s,a,b,c,top);
				PUSH(s,a-1,t,b,top);
			}
		}
	}
	cout<<"最终结果是:"<<t<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -