#include <stdio.h>#include<tchar.h>#include<stdlib.h>#defineStackSize 5#defineIncrementsize 5//TODO: Refer to other header files required by the program herestructstack{int*Base; int*top; intstacksize;};//Initialize StackBOOLInit_stack (stack*s) {s-Base= (int*)malloc(stacksize*sizeof(int)); if(s->Base= = NULL)return false; S->top = s->Base; S->stacksize =StackSize; return true;}//Destroying StacksBOOLDestroy_stack (stack*s) { Free(s->Base); S-Base=NULL; S->top =NULL; S->stacksize =0; return true;}//Empty StackBOOLClear_stack (stack*s) {s->top = s->Base; return true;}//inserting elementsBOOLPush (stack* S,intvalue) { if(s->top-s->Base>= s->stacksize) {s-Base= (int*)realloc(s->Base, (StackSize + incrementsize) *sizeof(int)); S->top = s->Base+ s->stacksize;//Reset The top of the stack, it doesn't feel very necessary.S->stacksize + =incrementsize; } *++s->top = value;//stack top points to top of stack elementss->stacksize++; return true;}//Popup ElementsintPop (stack*s) { if(S->top = = s->Base)return false; intp = *s->top--; S->stacksize--; returnp;}//Reverse PrintvoidPrint_stack (Stack s) {if(S.top = = S.)Base) printf ("this stack is empty \ n"); while(S.top!=s.Base) {printf ("%d->", Pop (&s)); } printf ("\ n");}//Positive Order PrintingvoidStack_traverse (Stack s) {if(S.top = = S.)Base) printf ("this stack is empty \ n"); while(S.top! = S.)Base) {printf ("%d->", *++s.Base); } printf ("\ n");}
C language implementation of basic data structure (iii) stack