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 (vf == 50)
- 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;
- }
- void settop1(int x) {
- st_x[vf] = x;
- }
- void settop2(int y) {
- st_y[vf] = y;
- }
- 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() {
- int i;
- for (i = 0; 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);
- }
- else 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);
- printf("%d %d ", st_x[vf], st_y[vf]);
- printf("\n%d\n", gettop2() + 1);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment