进出栈代码如下
#include<stdio.h>
#include<stdlib.h>
#define M 100
typedef struct {
int data[M];
int top;
}SqStack;
int InitSqStack(SqStack *S)
{
S->top=-1;
return 1;
}
int PushSqStack(SqStack *S,int e)
{
if(S->top==M-1)
{
return 0;
}
S->top++;
S->data[S->top]=e;
return 1;
}
int PopSqStack(SqStack *S,int *e)
{
if(S->top==-1)
{
return 0;
}
*e=S->data[S->top--];
return 1;
}
int main()
{
SqStack S;
int e,j;
InitSqStack(&S);
PushSqStack(&S,4);
PushSqStack(&S,8);
PushSqStack(&S,10);
PushSqStack(&S,78);
PushSqStack(&S,49);
for(j=0;j<M;j++)
{
if(PopSqStack(&S,&e)){
printf("%d ",e);
}
}
printf("\n");
return 0;
}
