3 #define MAX_STACK_SIZE 16
10 struct data data
[MAX_STACK_SIZE
];
14 static void stack_init(struct stack
*stack
)
19 static int stack_emty(const struct stack
*stack
)
21 return stack
->top
== 0;
24 static int stack_size(const struct stack
*stack
)
29 static int stack_push(struct stack
*stack
, struct data
*data
)
31 if (stack_size(stack
) >= MAX_STACK_SIZE
)
34 stack
->data
[stack
->top
] = *data
;
39 static int stack_pop(struct stack
*stack
, struct data
*data
)
41 if (stack_emty(stack
))
47 *data
= stack
->data
[stack
->top
];
51 static void fill_data(struct data
*data
, int code
)
59 struct data data
, data1
, data2
, data3
, data4
;
63 if (stack_emty(&stack
))
64 printf("Stack is empty\n");
66 printf("Stack is not empty\n");
73 stack_push(&stack
, &data1
);
74 stack_push(&stack
, &data2
);
75 stack_push(&stack
, &data3
);
76 stack_push(&stack
, &data4
);
78 if (stack_emty(&stack
))
79 printf("Stack is empty\n");
81 printf("Stack is not empty\n");
83 printf("Stack's size: %d\n", stack_size(&stack
));
85 while (stack_pop(&stack
, &data
) == 0)
86 printf("%d\n", data
.code
);
88 if (stack_emty(&stack
))
89 printf("Stack is empty\n");
91 printf("Stack is not empty\n");