Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAXSIZE 10
- struct stack
- {
- int stk[MAXSIZE];
- int top;
- };
- typedef struct stack STACK;
- STACK s;
- void push(void);
- int pop(void);
- void display(void);
- void main ()
- {
- int choice;
- int option = 1;
- s.top = -1;
- printf ("quiz1\n");
- while (option)
- {
- printf ("\n");
- printf (" 1 --> PUSH \n");
- printf (" 2 --> POP \n");
- printf (" 3 --> DISPLAY \n");
- printf (" 4 --> EXIT \n");
- printf ("\n");
- printf ("Tercihinizi girin\n");
- scanf ("%d", &choice);
- switch (choice)
- {
- case 1:
- push();
- break;
- case 2:
- pop();
- break;
- case 3:
- display();
- break;
- case 4:
- return;
- }
- fflush (stdin);
- printf ("Devam etmek istiyor musunuz(Type 0 or 1)?\n");
- scanf ("%d", &option);
- }
- }
- void push ()
- {
- int num;
- if (s.top == (MAXSIZE - 1))
- {
- printf ("Stack doldu\n");
- return;
- }
- else
- {
- printf ("PUSH giriniz\n");
- scanf ("%d", &num);
- s.top = s.top + 1;
- s.stk[s.top] = num;
- }
- return;
- }
- int pop ()
- {
- int num;
- if (s.top == - 1)
- {
- printf ("Stack bos\n");
- return (s.top);
- }
- else
- {
- num = s.stk[s.top];
- printf ("poplanan kisim = %dn", s.stk[s.top]);
- s.top = s.top - 1;
- }
- return(num);
- }
- void display ()
- {
- int i;
- if (s.top == -1)
- {
- printf ("Stack bos\n");
- return;
- }
- else
- {
- printf ("\n stack durumu \n");
- for (i = s.top; i >= 0; i--)
- {
- printf ("%d\n", s.stk[i]);
- }
- }
- printf ("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement