Advertisement
Cristina_Hustea

Untitled

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