mystack_e.cpp

来自「中缀表达式转中缀表达式」· C++ 代码 · 共 48 行

CPP
48
字号
#ifndef MYSTACK_E_H
#define MYSTACK_E_H

#include"mystack.h"

template<class DataType>
SepStack<DataType>::SepStack(){
	pdata = new DataType [MaxNum];
	if (pdata==NULL)
		cout<<"There is no space!\n";
	else
		t = -1;
}

template<class DataType>
int SepStack<DataType>::isEmptyStack(){
	return(t==-1);
}

template<class DataType>
void SepStack<DataType>::push(DataType x){
	if (t<MaxNum-1)
	{
		t++;
		pdata[t] = x;
	}
	else cout<<"Stack is full!!\n";
}

template<class DataType>
DataType SepStack<DataType>::pop(){
	assert(!isEmptyStack());
	return pdata[t--];
}

template<class DataType>
DataType SepStack<DataType>::top(){
	//if the stack is not empty
	return(pdata[t]);
}

template<class DataType>
void SepStack<DataType>::clear(){
	t = -1;
	delete [] pdata;
}

#endif

⌨️ 快捷键说明

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