Question: 5) Consider a queue and stack structures. You can use these two structures to reverse a list of numbers. Write a program in which a
5) Consider a queue and stack structures. You can use these two structures to reverse a list of numbers. Write a program in which a user is prompted to enter positive integer numbers, use a sentinel value to terminate the input. Enter user input in to a queue, when entry is complete, remove integers from the queue, display them and push them on top of a stack. Finally pop elements from stack and print them.
Recall Sentinel values, in this case you can you -1 as the Sentinel value. Have user keep entering positive integers until -1 is entered. You will then need to keep inserting into the queue, then pop from the queue, print and push on top of stack. When queue is empty, start popping from the stack and print the value popped.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
