stack2.h

来自「编译原理实验」· C头文件 代码 · 共 52 行

H
52
字号
class stack{		//定义一个栈,存放表达式的数据
public:
	double Vec[100];
	int MaxSize;
	int top;
public:
	stack()
	{top=-1;MaxSize=100;}
	~stack(){};
	void Push(double x);
	double Pop();
	double GetTop();
	void Clear(){top=-1;}
	int IsEmpty()
	{
		if(top==-1)
			return 1;
		else
			return 0;
	}
}array;
void stack::Push(double x)
{
	if(top==MaxSize-1)
		cout<<"overflow!"<<endl;
	else
	{
		top++;
		Vec[top]=x;
	}
}
double stack::Pop()
{
	double temp;
	if(top==-1)
		cout<<"underflow!"<<endl;
	else
	{
		temp=Vec[top];
		top--;
		return temp;
	}
	return -1;
}
double stack::GetTop()
{
	if(top==-1)
		cout<<"underflow!"<<endl;
	else
		return Vec[top];
	return -1;
}

⌨️ 快捷键说明

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