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

📄 seqstack.h

📁 算术表达式求值,数据结构课程设计,非常实用,适合学生
💻 H
字号:
template <class DataType>
class SeqStack
{
private:
	DataType data[MaxStackSize];
	int top;
public:
	SeqStack(void)
	{
		top=0;
	}
	~SeqStack(void){};
	void Push(const DataType &item);
	DataType Pop(void);
	DataType Peek(void) const;
	int StackEmpty(void)const
	{
		return(top==0);
	}
	int GetSize(void)const
	{
		return top;
	}
	void ClearStack(void)
	{
		top=0;
	}	
};
template <class DataType>
void SeqStack<DataType>::Push(const DataType &item)
{
	if(top==MaxStackSize)
	{
		cout<<"堆栈已满"<<endl;
		exit(0);
	}
	data[top]=item;
	top++;
}

template <class DataType>
DataType SeqStack<DataType>::Peek(void)const
{
	if(top==0)
	{
		cout<<"堆栈已空"<<endl;
		exit(0);
	}
	return data[top-1];
}//取top-1上的元素返回

template <class DataType>
DataType SeqStack<DataType>::Pop()
{
	if(top==0)
	{
		cout<<"堆栈已空!"<<endl;
		exit(0);
	}
	top--;
	return data[top];
}

⌨️ 快捷键说明

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