#include <iostream>
#include "MyStack.h"
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv)
{
MyStack *pStack=new MyStack(5);
if(pStack->stackEmpty())
{
cout<<"kong"<<endl;
}
else
{
cout<<"mei kong"<<endl;
}
if(pStack->stackFull())
{
cout<<"man"<<endl;
}
else
{
cout<<"mei man"<<endl;
}
delete []pStack;
pStack=NULL;
return 0;
}
class MyStack
{
public:
MyStack(int size);
~MyStack();
bool stackEmpty();//ÅпÕ
bool stackFull();//ÅÐÂú
void clearStack();//Çå¿Õ
int stackLength();//ÔªËظöÊý
bool push(char elem);//ÈëÕ»
bool pop(char &elem);//³öÕ»
void stackTraverse(bool isFromButtom);//±éÀú
private:
char *m_pBuffer;
int m_iSize;
int m_iTop;
};
#include "MyStack.h"
#include <iostream>
using namespace std;
MyStack::MyStack(int size)
{
m_iSize=size;
m_pBuffer=new char[m_iSize];
m_iTop=0;
}
MyStack::~MyStack()
{
delete []m_pBuffer;
m_pBuffer=NULL;
}
bool MyStack::stackEmpty()
{
if(0==m_iTop)
{
return true;
}
else
{
return false;
}
}
bool MyStack::stackFull()
{
if(m_iSize==m_iTop)
{
return true;
}
else
{
return false;
}
}
void MyStack::clearStack()
{
m_iTop=0;
}
int MyStack::stackLength()
{
return m_iTop;
}
bool MyStack::push(char elem)
{
if(!stackFull())
{
m_pBuffer[m_iTop]=elem;
m_iTop++;
return true;
}
else
{
return false;
}
}
bool MyStack::pop(char &elem)
{
if(!stackEmpty())
{
m_iTop--;
elem=m_pBuffer[m_iTop];
return true;
}
else
{
return false;
}
}
void MyStack::stackTraverse(bool isFromButtom)
{
if(isFromButtom)
{
for(int i=0;i<m_iTop;i++)
{
cout<<m_pBuffer[i]<<endl;
}
}
else
{
for(int i=m_iTop-1;i>=0;i--)
{
cout<<m_pBuffer[i]<<endl;
}
}
}