Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define MAXSIZE 10
  4.  
  5.  
  6.  
  7. struct stack
  8.  
  9. {
  10.  
  11. int stk[MAXSIZE];
  12.  
  13. int top;
  14.  
  15. };
  16.  
  17. typedef struct stack STACK;
  18.  
  19. STACK s;
  20.  
  21.  
  22.  
  23. void push(void);
  24.  
  25. int pop(void);
  26.  
  27. void display(void);
  28.  
  29.  
  30.  
  31. void main ()
  32.  
  33. {
  34.  
  35. int choice;
  36.  
  37. int option = 1;
  38.  
  39. s.top = -1;
  40.  
  41.  
  42.  
  43. printf ("quiz1\n");
  44.  
  45. while (option)
  46.  
  47. {
  48.  
  49. printf ("\n");
  50.  
  51. printf (" 1 --> PUSH \n");
  52.  
  53. printf (" 2 --> POP \n");
  54.  
  55. printf (" 3 --> DISPLAY \n");
  56.  
  57. printf (" 4 --> EXIT \n");
  58.  
  59. printf ("\n");
  60.  
  61.  
  62.  
  63. printf ("Tercihinizi girin\n");
  64.  
  65. scanf ("%d", &choice);
  66.  
  67. switch (choice)
  68.  
  69. {
  70.  
  71. case 1:
  72.  
  73. push();
  74.  
  75. break;
  76.  
  77. case 2:
  78.  
  79. pop();
  80.  
  81. break;
  82.  
  83. case 3:
  84.  
  85. display();
  86.  
  87. break;
  88.  
  89. case 4:
  90.  
  91. return;
  92.  
  93. }
  94.  
  95. fflush (stdin);
  96.  
  97. printf ("Devam etmek istiyor musunuz(Type 0 or 1)?\n");
  98.  
  99. scanf ("%d", &option);
  100.  
  101. }
  102.  
  103. }
  104.  
  105.  
  106.  
  107. void push ()
  108.  
  109. {
  110.  
  111. int num;
  112.  
  113. if (s.top == (MAXSIZE - 1))
  114.  
  115. {
  116.  
  117. printf ("Stack doldu\n");
  118.  
  119. return;
  120.  
  121. }
  122.  
  123. else
  124.  
  125. {
  126.  
  127. printf ("PUSH giriniz\n");
  128.  
  129. scanf ("%d", &num);
  130.  
  131. s.top = s.top + 1;
  132.  
  133. s.stk[s.top] = num;
  134.  
  135. }
  136.  
  137. return;
  138.  
  139. }
  140.  
  141.  
  142.  
  143. int pop ()
  144.  
  145. {
  146.  
  147. int num;
  148.  
  149. if (s.top == - 1)
  150.  
  151. {
  152.  
  153. printf ("Stack bos\n");
  154.  
  155. return (s.top);
  156.  
  157. }
  158.  
  159. else
  160.  
  161. {
  162.  
  163. num = s.stk[s.top];
  164.  
  165. printf ("poplanan kisim = %dn", s.stk[s.top]);
  166.  
  167. s.top = s.top - 1;
  168.  
  169. }
  170.  
  171. return(num);
  172.  
  173. }
  174.  
  175.  
  176.  
  177. void display ()
  178.  
  179. {
  180.  
  181. int i;
  182.  
  183. if (s.top == -1)
  184.  
  185. {
  186.  
  187. printf ("Stack bos\n");
  188.  
  189. return;
  190.  
  191. }
  192.  
  193. else
  194.  
  195. {
  196.  
  197. printf ("\n stack durumu \n");
  198.  
  199. for (i = s.top; i >= 0; i--)
  200.  
  201. {
  202.  
  203. printf ("%d\n", s.stk[i]);
  204.  
  205. }
  206.  
  207. }
  208.  
  209. printf ("\n");
  210.  
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement