Q28
The result evaluating the postfix expression is
Show answer without attempting
Answer: C
GATE CS · Linear Data Structures · 2 questions
2 Stacks questions from GATE CS papers (2015), each with the official answer key. Part of Linear Data Structures. Answer any question right here and it is marked straight away, or practise them one at a time.
Answer: C
#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));
}Answer: 15
0/20 correct0 marks