#include <stdio.h> #include <stdlib.h> #define MAX_SIZE 5 typedef struct Stack { int top; int data[MAX_SIZE]; }Stack; Stack* initStack() { Stack *s = (Stack *)malloc(sizeof(Stack)); s->top = 0; for(int i = 0; i < MAX_SIZE; i++) { s->data[i] = 0; } return s; } int push(Stack *s, int value) { if(s->top == MAX_SIZE - 1) { return -1; } s->top++; s->data[s->top] = value; return 0; } int pop(Stack *s) { if(s->top == -1) { return -1; } int v = s->data[s->top]; s->top--; return v; } void main() { Stack *s = initStack(); push(s, 10); push(s, 20); push(s, 30); push(s, 40); printf("%d\n", pop(s)); }