#include "stdio.h"
#include "malloc.h"
#define MAX 100
typedef struct SeqStack
{
int s[MAX];
int t;
}*PSeqStack;
PSeqStack createEmptyStack_seq()
{
PSeqStack pastack;
pastack=(SeqStack*)malloc(sizeof(SeqStack));
if(pastack==NULL)
printf("Out of space!\n");
else
pastack->t=-1;
return pastack;
}
int isEmptyStack_seq(PSeqStack pastack)
{
return (pastack->t==-1);
}
void push_seq(PSeqStack pastack,int x)
{
if(pastack->t>=MAX-1)
printf("Overflow!\n");
else
{
pastack->t=pastack->t+1;
pastack->s[pastack->t]=x;
}
}
void pop_seq(PSeqStack pastack)
{
if(pastack->t==-1)
printf("Underflow!\n");
else
pastack->t=pastack->t-1;
}
int top_seq(PSeqStack pastack)
{
return(pastack->s[pastack->t]);
}
int main()
{
PSeqStack pastack;
int N;
printf("Please input number to N!\n");
scanf("%d",&N);
pastack=createEmptyStack_seq();
for(int i=0;i<N;i++)
{
int x;
printf("Please input number to stack!\n");
scanf("%d",&x);
push_seq(pastack,x);
}
printf("The top number is %d",top_seq(pastack));
}