#define MAXSIZE 100
typedef struct
{
char elem[MAXSIZE];
int top;
}stStack;
void InitStack(stStack*& s);
int Push(stStack*& s, char e);
char Pop(stStack*& s);
int _tmain(int argc, _TCHAR* argv[])
{
char e;
stStack* s;
InitStack(s);
Push(s, 'a');
Push(s, 'b');
while(s->top>=0)
{
e = Pop(s);
cout<<"e="<<e<<endl;
}
free s;
system("pause");
return 0;
}
void InitStack(stStack*& s)
{
s = (stStack*)malloc(sizeof(stStack));
s->top = -1;
}
int Push(stStack*& s, char e)
{
if(s->top == MAXSIZE-1)
return 0;
s->top++;
s->elem[s->top] = e;
return 1;
}
char Pop(stStack*& s)
{
char e;
if(s->top == -1)
return 0;
e = s->elem[s->top];
s->top --;
return e;
}