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