#include <stdio.h>
int *A, stkTop;
int stkFunc(int opcode, int val) {
static int size = 0, stkTop = 0;
switch (opcode) {
case -1: size = val; break;
case 0: if (stkTop < size) A[stkTop++] = val; break;
default: if (stkTop) return A[--stkTop];
}
return -1;
}
int main() {
int B[20]; A = B; stkTop = -1;
stkFunc(-1, 10);
stkFunc(0, 5);
stkFunc(0, 10);
printf("%d\n", stkFunc(1, 0) + stkFunc(1, 0));
}Related Programming & Data Structures PYQs
Consider the following New-order strategy for traversing a binary tree: • Visit the root; • Visit the right subtree using New-orde…
Consider the following array of elements. 〈89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100〉. The minimum number of interchanges nee…
What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes o…
Consider the following C program segment. ```c #include <stdio.h> int main() { char s1[7] = "1234", *p; p = s1 + 2; *p…
Consider the following C program. ```c #include <stdio.h> int main() { static int a[] = {10, 20, 30, 40, 50}; static int *…
A Young tableau is a 2D array of integers increasing from left to right and from top to bottom. Any unfilled entries are marked wi…
Free account benefits
Turn practice into measurable progress
Public PYQs and reference pages stay free. Sign in when you want GATEverse to remember what you studied and guide what to practise next.