Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <math.h>
- #include <string.h>
- #define MAX 100
- int t, i, j = 0, k, l, a, b, c, d, n, x, y, z;
- int ar[MAX];
- int top = 0;
- void stack()
- {
- puts("Press Any key to continue");
- puts("1 --> push");
- puts("2 --> pop");
- puts("3 --> exit");
- }
- void push()
- {
- if (j >= MAX) printf("Stack full\n");
- else
- {
- printf("Item to push:");
- scanf("%d", &ar[j]);
- j++;
- top = j;
- printf("Item %d has been pushed\n", ar[j - 1]);
- }
- }
- int pop()
- {
- if (top == 0) {puts("Stack empty, invalid operation"); return 0;}
- else
- {
- x = ar[j - 1];
- ar[j - 1] = 0;
- j--;
- return x;
- }
- }
- int main()
- {
- for (; ;)
- {
- void stack();
- scanf("%d", &n);
- if (n == 3) break;
- if (n == 1)
- {
- push();
- }
- else if (n == 2)
- {
- z = pop();
- if (z)printf("Item %d has been popped\n", z);
- }
- else puts("Ooops...try again");
- }
- for (i = 0; i < j; i++)
- printf("%d ", ar[j]);
- puts("");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement