class MyStack
{
private:
int m_size;
int m_top;
char *m_pStack;
public:
MyStack::MyStack(int _size):m_size(_size),m_top(0){
m_pStack=new char[_size];
}
MyStack::~MyStack(){
delete []m_pStack;
m_pStack=NULL;
}
bool MyStack::StackEmpty(){
if(0==m_top) return true;
return false;
}
bool MyStack::StackFull(){
if(m_top==m_size) return true;
return false;
}
void MyStack::clearStack(){
m_top=0;
}
bool MyStack::pushStack(char elem){
if(StackFull()) return false;
m_pStack[m_top]=elem;
m_top++;
return true;
}
char MyStack::popStack(){
if(StackEmpty()) return -1;
m_top--;
return m_pStack[m_top];
}
void MyStack::stackTraverse(){
for(int i=0;i<m_top;i++)
cout<<m_pStack[i]<<","<<endl;
}
};
栈的构建
最新推荐文章于 2022-07-19 17:10:14 发布