Ask Question

What is written by the following algorithm?

Push (myStack, 5) Push (myStack, 4) Push (myStack, 3) Pop (myStack, item) item = item * 2Pop (myStack, item) item = item / 2Push (myStack, item) WHILE (NOT IsEmtpy (myStack)) Pop (myStack, item) Write item, '

+3
Answers (1)
  1. 6 October, 10:33
    0
    The code prints 2 5.

    Explanation:

    Stack after all insertions is: 3 (top),4,5 (bottom)

    Pop (myStack, item) it will pop 3.

    4 is popped and divided by 2 and again pushed. Stack here is : 2,5

    So, final popping of all remaining elements will result in output of 2 5
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What is written by the following algorithm? Push (myStack, 5) Push (myStack, 4) Push (myStack, 3) Pop (myStack, item) item = item * 2Pop ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers