#include <stdio.h>
#include <stdlib.h>
#define MAX_NUM 10
typedef int datatype;
typedef struct _SEQSTACK
{
datatype data[MAX_NUM];
int top;
}SeqStack;
SeqStack* init_stack()
{
SeqStack* thiz=(SeqStack)malloc(sizeof(SeqStack));
if(thiz==NULL)
{
printf("init_stack is error /n");
}
thiz->top=-1;
return thiz;
}
void destory_stack(SeqStack* thiz)
{
if(thiz!=NULL)
{
free(thiz);
thiz=NULL;
}
}
void push_stack(SeqStack* thiz)
{
if(!full_stack())
{
thiz->data[++(thiz->top)]=data;
}
}
int pop_stack(SeqStack* thiz)
{
if(!empty_stack())
{
return thiz->data[(thiz->top)--];
}
}
int empty_stack(SeqStack* thiz)
{
if(thiz->top<0)
{
return 1;
}
return 0;
}
int full_stack(SeqStack* thiz)
{
if((thiz->top)>=(MAX_NUM-1))
{
return 1;
}
return 0;
}
void print_stack(SeqStack* thiz)
{
if(thiz!=NULL)
{
int i=thiz->top;
while(i>=0)
{
printf("%d /n",thiz->data[i]);
i--;
}
}
}
int main(void)
{
int i=0;
SeqStack* thiz=init_stack();
for(; i<6; i++)
{
push_back(thiz,i);
}
print_stack(thiz);
i=pop_stack(thiz);
printf("----------------/n");
printf("%d /n",i);
return 0;
}