#include"sequence_stack.h"
seqstack *create_seqstack(int len){
seqstack * H;if((H =(seqstack *)malloc(sizeof(seqstack)))==NULL){printf("malloc no memory!\n");returnNULL;}if((H->data =(datatype *)malloc(len *sizeof(datatype)))==NULL){printf("malloc no memory!\n");returnNULL;}
H->maxlen = len;
H->top =-1;return H;}voidclear_seqstack(seqstack *L){
L->top =-1;}voidfree_seqstack(seqstack *L){free(L->data);
L->data =NULL;free(L);
L =NULL;}intis_empty_seqstack(seqstack *L){return(L->top ==-1?1:0);}intis_full_seqstack(seqstack *L){return(L->top ==(L->maxlen-1)?1:0);}intpush_seqstack(seqstack *L,datatype x){if(is_full_seqstack(L)){printf("stack is full!\n");return-1;}else{
L->top++;
L->data[L->top]= x;return0;}}
datatype pop_seqstack(seqstack *L){if(is_empty_seqstack(L)){printf("stack is empty!\n");return-1;}else{
L->top--;return L->data[L->top+1];}}
datatype get_top_seqstack(seqstack *L){if(is_empty_seqstack(L)){printf("stasic is empty!\n");return-1;}else{return L->data[L->top];}}
main.c
#include"sequence_stack.h"intmain(int argc,constchar*argv[]){int n =5;
seqstack *S;
S =create_seqstack(n);push_seqstack(S,10);push_seqstack(S,20);push_seqstack(S,30);push_seqstack(S,40);push_seqstack(S,50);push_seqstack(S,60);printf("%d\n",get_top_seqstack(S));while(!is_empty_seqstack(S)){printf("%d\t",pop_seqstack(S));}puts("");printf("%d\n",get_top_seqstack(S));free_seqstack(S);printf("%d\n",get_top_seqstack(S));return0;}