// // stack.c // // // Created by Bibhas Ghoshal on 18/04/23. // #include #define SIZE 100 //typedef struct { // int key; /* just an example, can have Declaration any type of // fields depending on what is to be stored */ //} element; typedef struct { //element list[SIZE]; int list[SIZE]; int top; /* index of the topmost element */ } stack; int isfull (stack *s) { if (s->top >= SIZE-1) return 1; return 0; } int isempty (stack *s) { if (s->top == -1) return 1; return 0; } int top( stack *s ) { return s->list[s->top]; } void push( stack *s, int element) { (s->top)++; s->list[s->top] = element; } int pop( stack *s ) { int x = s->list[s->top]; (s->top)--; return x; } int main() { stack Z; Z.top = -1; /* Push elements */ push(&Z,10); printf("\n Top = %d and element pushed = %d \n",Z.top,Z.list[0]); push(&Z,20); printf("\n Top = %d and element pushed = %d \n",Z.top,Z.list[1]); /* Pop the elements and print */ printf("\n %d %d \n",pop(&Z),pop(&Z)); }