What are the contents of the stack after running the following algorithm? Given
ID: 3669432 • Letter: W
Question
What are the contents of the stack after running the following algorithm? Given an array and an empty stack: Push the values of the array onto the stack until a - 1 value is found. Do not push the -1. Pop the values in the stack until an even value is found or the stack is empty. The even value should be popped. Repeat steps 1 and 2 until the stack is full or the array is read completely. Type the contents of the stack from top to bottom, separated by a space, in the Answer box. If the stack is empty, enter a 0. For this problem, use an array = {10, -1, 3, 2, 3, -1, 4, 5, 7, 8, 6, 2, -1}, and a stack size of 6.Explanation / Answer
Assumption: If the stack is full while reading from the array, then the program quits
a = {10,-1,3,2,3,-1,4,5,7,8,6,2,-1}
1st Iteration:
1. Stack 10
2. Stack empty
2nd Iteration:
1. Stack 3,2,3
2. Stack 3
3rd Iteration:
1. Stack 3 4 5 7 8 6 Now the stack is full hence end of program
Answer = 6 8 7 5 4 3
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.