Colored By Color Scripter™
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <stdio.h> #define MAX 2 int stack[MAX]; int top = -1; void push(int value) { if (top >= MAX - 1) { printf("Error\n"); return; } stack[++top] = value; } int pop(void) { if (top < 0) { printf("Error\n"); return 0; } return stack[top--]; } int main() { push(3); push(4); push(5); printf("%d ----\n", pop()); printf("%d ---\n", pop()); push(5); printf("%d --\n", pop()); printf("%d -\n", pop()); } |