#include<stdio.h>#include<stdlib.h>#include<string.h>#include"sqstack.h"sqstack*stack_create(intlen){sqstack*s;if((s=(sqstack*)malloc(sizeof(sqstack)))==NULL){printf("malloc sqstack failed\n");returnNULL;}if((s->data=(data_t*)malloc(len*sizeof(data_t)))==NULL){printf("malloc data failed\n");free(s);returnNULL;}memset(s->data,0,len*sizeof(data_t));s->maxlen=len;s->top=-1;returns;}intstack_push(sqstack*s,data_tvalue){if(s==NULL){printf("s is NULL\n");return-1;}if(s->top==s->maxlen-1){printf("stack is full\n");return-1;}s->top++;s->data[s->top]=value;return0;}intstack_empty(sqstack*s){if(s==NULL){printf("s is NULL\n");return-1;}return(s->top==-1?1:0);}intstack_full(sqstack*s){if(s==NULL){printf("s is NULL\n");return-1;}return(s->top==s->maxlen-1?1:0);}data_tstack_pop(sqstack*s){s->top--;return(s->data[s->top+1]);}data_tstack_top(sqstack*s){return(s->data[s->top]);}intstack_clear(sqstack*s){if(s==NULL){printf("s is NULL\n");return-1;}s->top=-1;return0;}intstack_free(sqstack*s){if(s==NULL){printf("s is NULL\n");return-1;}if(s->data!=NULL){free(s->data);}free(s);return0;}