存存 自己作业写的😎😎
#include<stdio.h>
#define MAXSIZE 100
typedef int elemtype;
typedef struct
{
elemtype *top,*base;
int length;
}sqstack;
int initstack(sqstack *S)
{
S->base=(sqstack *)malloc(sizeof(MAXSIZE));
if(!S->base)
return 0;
S->top=S->base;
S->length=MAXSIZE;
return 1;
}
int pushlist(sqstack *S,int n)//入栈
{
while(S->top-S->base!=n)
{
scanf("%d",S->top++);
}
}
void printlist(sqstack *S)
{
int i;
for(i=S->top;i>=S->base;i--)
{
printf("%d ",*(S->base++));
}
}
void Pop(sqstack *S)//出栈
{
int e;
while(S->top!=S->base)
e=*--S->top;
}
int main()
{
int i;
sqstack S;
initstack(&S);
pushlist(&S,5);
printlist(&S);
Pop(&S);
printlist(&S);
return 0;
}