ProgrammingHardAccenture · TCS · Infosys
What is the final content of the stack (bottom to top, left to right) after this sequence of operations on an initially empty stack?
What is the final content of the stack (bottom to top, left to right) after this sequence of operations on an initially empty stack?
push 93 push 88 push 26 push 81 pop push 87 pop
- A. 93, 88, 26
- B. 93, 88, 26, 87
- C. 26, 88, 93
- D. 26, 81, 87
Correct answer: A. 93, 88, 26
Tracing push/pop on an empty stack in order gives, bottom-to-top, [93, 88, 26]. Reading top-to-bottom instead gives the reversed trap [26, 88, 93]; mistakenly treating "pop" as removing the front (as in a queue) gives [26, 81, 87].
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (Arrays are passed and assigned BY REFERENCE: b = a makes b point to the same array…
- What will be the output of the following pseudocode? (^ is bitwise XOR.) Integer x = 98, y = 21 x = x ^ y y = x ^ y x = x ^ y Print x, y
- What will be the output of the following pseudocode? (A square matrix's main diagonal is mat[i][i]; its anti-diagonal is mat[i][n-1-i]. If…
- What will be the output of the following pseudocode? Function isEven(Integer n) if (n == 0) return true end if return isOdd(n - 1) end…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer x, y Set x = 17, y =…
- What will be the output of the following pseudocode? Integer s = 0 for (each i from 1 to 10) if (i mod 2 == 0) s = s + i end if end for…