Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h>
- #include<stdlib.h>
- int vf = -1, st_x[50], st_y[50];
- int full() {
- if (st_x[vf] == 49 && st_y[vf] == 49)
- return 1;
- return 0;
- }
- void push(int x, int y) {
- if (full()) {
- printf("stiva plina");
- }
- else {
- vf++;
- st_x[vf] = x;
- st_y[vf] = y;
- }
- }
- int pop(int *x, int *y) {
- *x = st_x[vf];
- *y = st_y[vf];
- vf--;
- return vf;
- }
- int settop1(int x) {
- return st_x[vf];
- }
- int settop2(int y) {
- return st_y[vf];
- }
- int gettop1() {
- if (vf >= 0)
- return st_x[vf];
- else return -1;
- }
- int gettop2() {
- if (vf >= 0)
- return st_y[vf];
- else return -1;
- }
- void printStack() {
- for (int i = 1; i <= vf; i++)
- printf("%d %d \n", st_x[i], st_y[i]);
- printf("\n");
- }
- int main() {
- int vfnew = 0, ynew = 0;
- int a = 0, b = 0, c = 0;
- int x = 2, y = 1;
- push(x, y);
- do {
- printStack();
- if (st_x[vf] == 0) {
- pop(&x,&y);
- c = gettop2();
- pop(&x,&y);
- settop1(0);
- settop2(c + 1);
- }
- if (st_y[vf] == 0) {
- a = gettop1();
- pop(&x,&y);
- push(a - 1, 1);
- }
- else
- {
- a = gettop1();
- b = gettop2();
- push(a, b - 1);
- }
- } while (vf != 0);
- printf("%d %d ", st_x[vf], st_y[vf]);
- printf("%d", gettop2() + 1);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement