Alx09

Untitled

Mar 31st, 2020
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int vf = -1, st_x[50], st_y[50];
  6.  
  7. int full() {
  8. if (vf == 50)
  9. return 1;
  10. return 0;
  11. }
  12.  
  13. void push(int x, int y) {
  14. if (full()) {
  15. printf("stiva plina");
  16. }
  17. else {
  18. vf++;
  19. st_x[vf] = x;
  20. st_y[vf] = y;
  21.  
  22. }
  23. }
  24. int pop(int *x, int *y) {
  25. *x = st_x[vf];
  26. *y = st_y[vf];
  27.  
  28. vf--;
  29. return vf;
  30. }
  31.  
  32. void settop1(int x) {
  33. st_x[vf] = x;
  34. }
  35. void settop2(int y) {
  36. st_y[vf] = y;
  37. }
  38. int gettop1() {
  39. if (vf >= 0)
  40. return st_x[vf];
  41. else return -1;
  42. }
  43. int gettop2() {
  44. if (vf >= 0)
  45. return st_y[vf];
  46. else return -1;
  47. }
  48. void printStack() {
  49. int i;
  50. for (i = 0; i <= vf; i++)
  51. printf("%d %d \n", st_x[i], st_y[i]);
  52. printf("\n");
  53. }
  54.  
  55. int main() {
  56. int vfnew = 0, ynew = 0;
  57. int a = 0, b = 0, c = 0;
  58. int x = 2, y = 1;
  59. push(x, y);
  60. do {
  61. printStack();
  62. if (st_x[vf] == 0) {
  63. pop(&x, &y);
  64. c = gettop2();
  65. pop(&x, &y);
  66. settop1(0);
  67. settop2(c + 1);
  68.  
  69. }
  70. else if (st_y[vf] == 0) {
  71. a = gettop1();
  72. pop(&x, &y);
  73. push(a - 1, 1);
  74.  
  75. }
  76. else
  77. {
  78. a = gettop1();
  79. b = gettop2();
  80. push(a, b - 1);
  81.  
  82. }
  83.  
  84.  
  85.  
  86. } while (vf);
  87. printf("%d %d ", st_x[vf], st_y[vf]);
  88. printf("\n%d\n", gettop2() + 1);
  89.  
  90.  
  91.  
  92. system("pause");
  93. return 0;
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment