Alx09

Untitled

Mar 31st, 2020
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define nMax 50
  5. int vf = 0, st_x[nMax], st_y[nMax];
  6.  
  7. void push(int x, int y) {
  8. if (vf == nMax) {
  9. printf("stiva plina");
  10. }
  11. else {
  12. vf++;
  13. st_x[vf] = x;
  14. st_y[vf] = y;
  15.  
  16. }
  17. }
  18.  
  19.  
  20.  
  21. void printStack() {
  22. int i;
  23. for (i = vf; i > 0; i--)
  24. printf("%d %d \n", st_x[i], st_y[i]);
  25. printf("\n");
  26. }
  27.  
  28. int main() {
  29.  
  30. int x = 2, y = 1;
  31. push(x, y);
  32. do {
  33. printStack();
  34. if (st_x[vf] == 0) {
  35. vf--;
  36. --st_x[vf];
  37. st_y[vf] = st_y[vf + 1] + 1;
  38. }
  39. else if (st_y[vf] == 0) {
  40. st_x[vf]--;
  41. st_y[vf] = 1;
  42. }
  43. else
  44. push(st_x[vf], st_y[vf] - 1);
  45.  
  46.  
  47.  
  48. } while (vf);
  49. printf("Rezultatul este: %d ", st_y[0]);
  50. system("pause");
  51. return 0;
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment