Stacks questions

Q28

GATE CS 2015 CS-3Linear Data StructuresMCQ1 mark−1/3 if wrong
The result evaluating the postfix expression 10  5  +  60  6  /  ∗  8  −10 \; 5 \; + \; 60 \; 6 \; / \; * \; 8 \; - is
Show answer without attempting

Answer: C

Q52

GATE CS 2015 CS-2Linear Data StructuresNAT2 marks
Consider the C program below.
#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));
}
The value printed by the above program is ___________.
Show answer without attempting

Answer: 15

0/20 correct0 marks

Related topics in Linear Data Structures