Write a pseudocode algorithm that uses two stacks to simulate one queue. Only co
ID: 641101 • Letter: W
Question
Write a pseudocode algorithm that uses two stacks to simulate one queue. Only consider insertions and deletions from the queue. Since this is pseudocode, you do not have to describe how to implement push and pop (these are the operations that you will discuss to simulate the queue). However, you may assume that these are acceptable terms to use within your pseudocode algorithm. Make sure that the algorithm clearly describes what needs to be done with the stack during insertions and deletions from the queue.
Explanation / Answer
function queuepush (obj) stack1.push(obj) function queuepop () if stack2 is empty if stack1 is empty return null while stack1 is not empty stack2.push(stack1.pop()) return stack2.pop()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.