#include <iostream>
#include "zhandetouwenjian.h"
using namespace std;
void shuchuzhan(sqstack * s)
{
for(int i=s->top;i>-1;i--)
cout<<s->shuju[i]<<" ";
cout<<endl;
}
int main()
{
sqstack * s;
A e;
zhandechushihua(s);
cout<<zhanpanduankong(s)<<endl;
e='a';
jinzhan(s,e);
e='b';
jinzhan(s,e);
e='c';
jinzhan(s,e);
e='d';
jinzhan(s,e);
e='e';
jinzhan(s,e);
cout<<zhanpanduankong(s)<<endl;
cout<<zhandechangdu(s)<<endl;
shuchuzhan(s);
for(int a=0;a<5;a++)
{
chuzhan(s,e);
cout<<e<<" "<<s->top+2<<endl;
}
cout<<zhanpanduankong(s)<<endl;;
zhandecuihui(s);
return 0;
}
#include <iostream>
#include <malloc.h>
#include "zhandetouwenjian.h"
void zhandechushihua(sqstack *& s)
{
s=(sqstack *)malloc(sizeof(sqstack));
s->top=-1;
}
void zhandecuihui(sqstack *& s)
{
free(s);
}
bool zhanpanduankong(sqstack * s)
{
if(s->top==-1)
return 1;
else
return 0;
}
bool jinzhan(sqstack *& s,A e)
{
if(s->top==zuida-1)
return false;
s->top++;
s->shuju[s->top]=e;
return true;
}
bool chuzhan(sqstack *& s,A &e)
{
if(s->top==-1)
return false;
e=s->shuju[s->top];
s->top--;
return true;
}
bool quzhanding(sqstack * s,A &e)
{
if(s->top==-1)
return false;
e=s->shuju[s->top];
return true;
}
int zhandechangdu(sqstack * s)
{
return (s->top+1);
}
#ifndef ZHANDETOUWENJIAN_H_INCLUDED
#define ZHANDETOUWENJIAN_H_INCLUDED
#define zuida 99
typedef char A;
typedef struct
{
A shuju[zuida];
int top;
}sqstack;
void zhandechushihua(sqstack *& s);
void zhandecuihui(sqstack *& s);
bool zhanpanduankong(sqstack * s);
bool jinzhan(sqstack *& s,A e);
bool chuzhan(sqstack *& s,A &e);
bool quzhanding(sqstack * s,A &e);
int zhandechangdu(sqstack * s);
void shuchuzhan(sqstack * s);
#endif // ZHANDETOUWENJIAN_H_INCLUDED